Skip to content

Commit

Permalink
add on_ready_counter to reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
weiwei authored and auvipy committed Jan 30, 2024
1 parent 8619ad0 commit 8bffa2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions billiard/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def __reduce__(self):
self.inq, self.outq, self.synq, self.initializer,
self.initargs, self.maxtasks, self._shutdown, self.on_exit,
self.sigprotection, self.wrap_exception, self.max_memory_per_child,
self.on_ready_counter
)

def __call__(self):
Expand Down
17 changes: 17 additions & 0 deletions t/unit/test_pool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import billiard.pool
from billiard import get_context
import time
import pytest

Expand All @@ -9,6 +10,12 @@ def func(x):
return x


def get_on_ready_count():
import inspect
worker = inspect.stack()[1].frame.f_locals['self']
return worker.on_ready_counter.value


class test_pool:
def test_raises(self):
pool = billiard.pool.Pool()
Expand Down Expand Up @@ -39,3 +46,13 @@ def test_exception_traceback_present(self):
if i == 2:
with pytest.raises(ValueError):
res.get()

def test_on_ready_counter_is_synchronized(self):
for ctx in ('spawn', 'fork', 'forkserver'):
pool = billiard.pool.Pool(processes=1, context=get_context(ctx))
pool.apply_async(func, (1,)).get(1)
on_ready_counter = pool.apply_async(get_on_ready_count, ).get(1)
assert on_ready_counter == 1
pool.close()
pool.join()
pool.terminate()

0 comments on commit 8bffa2c

Please sign in to comment.