Skip to content

Commit 13a6f49

Browse files
committed
multiprocessing: tests: Turn into proper tests, make CPython compatible.
1 parent 3e3c6fc commit 13a6f49

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

multiprocessing/test_pipe.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
import os
3-
from multiprocessing import Process, Pipe, Connection
3+
from multiprocessing import Process, Pipe
44

55
def f(conn):
66
conn.send([42, None, 'hello'])
@@ -9,11 +9,14 @@ def f(conn):
99

1010
if __name__ == '__main__':
1111
parent_conn, child_conn = Pipe(False)
12-
print(parent_conn, child_conn)
12+
#print(parent_conn, child_conn)
1313
p = Process(target=f, args=(child_conn,))
14+
1415
# Extension: need to call this for uPy
15-
p.register_pipe(parent_conn, child_conn)
16+
if sys.implementation.name == "micropython":
17+
p.register_pipe(parent_conn, child_conn)
18+
1619
p.start()
17-
print(parent_conn.recv())
18-
print(parent_conn.recv())
20+
parent_conn.recv() == [42, None, 'hello']
21+
parent_conn.recv() == [42, 42, 42]
1922
p.join()

multiprocessing/test_pool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ def f(x):
44
return x*x
55

66
pool = Pool(4)
7-
print(pool.apply(f, (10,)))
7+
assert pool.apply(f, (10,)) == 100

multiprocessing/test_pool_async.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ def f(x):
66

77
pool = Pool(4)
88
future = pool.apply_async(f, (10,))
9-
print(future.get())
9+
assert future.get() == 100
1010

1111
def f2(x):
12-
time.sleep(1)
12+
time.sleep(0.5)
1313
return x + 1
1414

1515
future = pool.apply_async(f2, (10,))
16+
iter = 0
1617
while not future.ready():
17-
print("not ready")
18-
time.sleep(0.2)
19-
20-
print(future.get())
18+
#print("not ready")
19+
time.sleep(0.1)
20+
iter += 1
2121

22+
assert future.get() == 11
23+
assert iter >= 5 and iter <= 8
2224

2325
t = time.time()
2426
futs = [
@@ -27,6 +29,7 @@ def f2(x):
2729
pool.apply_async(f2, (12,)),
2830
]
2931

32+
iter = 0
3033
while True:
3134
#not all(futs):
3235
c = 0
@@ -35,7 +38,10 @@ def f2(x):
3538
c += 1
3639
if not c:
3740
break
38-
print("not ready2")
39-
time.sleep(0.2)
41+
#print("not ready2")
42+
time.sleep(0.1)
43+
iter += 1
44+
45+
assert iter >= 5 and iter <= 8
4046

4147
print("Run 3 parallel sleep(1)'s in: ", time.time() - t)

multiprocessing/test_process.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from multiprocessing import Process
22

33
def f(name):
4-
print('hello', name)
4+
assert name == 'bob'
55

66
if __name__ == '__main__':
77
p = Process(target=f, args=('bob',))

0 commit comments

Comments
 (0)