Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit 15750ab

Browse files
committed
Wait for results to be ready
1 parent 5af098a commit 15750ab

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

demos/pool-map.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def f(x):
1212
# non-blocking alternative
1313
result = pool.map_async(f, range(10))
1414
while not result.ready():
15+
print("waiting...")
1516
time.sleep(1)
17+
1618
print(result.get())
1719

demos/pool.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from multiprocessing import Pool
2+
import time
23

34
def f(x):
45
return x**2
@@ -11,5 +12,9 @@ def f(x):
1112

1213
# Non-blocking execution "in the background"
1314
result = pool.apply_async(f, (12,))
15+
while not result.ready():
16+
print("waiting...")
17+
time.sleep(1)
18+
1419
print(result.get(timeout=1))
1520

0 commit comments

Comments
 (0)