Skip to content

Commit 8bffa2c

Browse files
weiweiauvipy
authored andcommitted
add on_ready_counter to reduction
1 parent 8619ad0 commit 8bffa2c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

billiard/pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def __reduce__(self):
271271
self.inq, self.outq, self.synq, self.initializer,
272272
self.initargs, self.maxtasks, self._shutdown, self.on_exit,
273273
self.sigprotection, self.wrap_exception, self.max_memory_per_child,
274+
self.on_ready_counter
274275
)
275276

276277
def __call__(self):

t/unit/test_pool.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import billiard.pool
2+
from billiard import get_context
23
import time
34
import pytest
45

@@ -9,6 +10,12 @@ def func(x):
910
return x
1011

1112

13+
def get_on_ready_count():
14+
import inspect
15+
worker = inspect.stack()[1].frame.f_locals['self']
16+
return worker.on_ready_counter.value
17+
18+
1219
class test_pool:
1320
def test_raises(self):
1421
pool = billiard.pool.Pool()
@@ -39,3 +46,13 @@ def test_exception_traceback_present(self):
3946
if i == 2:
4047
with pytest.raises(ValueError):
4148
res.get()
49+
50+
def test_on_ready_counter_is_synchronized(self):
51+
for ctx in ('spawn', 'fork', 'forkserver'):
52+
pool = billiard.pool.Pool(processes=1, context=get_context(ctx))
53+
pool.apply_async(func, (1,)).get(1)
54+
on_ready_counter = pool.apply_async(get_on_ready_count, ).get(1)
55+
assert on_ready_counter == 1
56+
pool.close()
57+
pool.join()
58+
pool.terminate()

0 commit comments

Comments
 (0)