Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-billiard for openSUSE:Factory 
checked in at 2026-11-20 14:47:08
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-billiard (Old)
 and      /work/SRC/openSUSE:Factory/.python-billiard.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-billiard"

Fri Nov 20 14:47:08 2026 rev:32 rq:1398853 version:4.3.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-billiard/python-billiard.changes  
2026-10-26 10:01:17.337950894 +0100
+++ 
/work/SRC/openSUSE:Factory/.python-billiard.new.1251/python-billiard.changes    
    2026-11-20 14:50:01.779768357 +0100
@@ -1,0 +2,14 @@
+Fri Nov 20 01:13:29 UTC 2026 - Steve Kowalik <[email protected]>
+
+- Update to 4.3.2:
+  * Fix flaky timeout and context availability in
+    test_on_ready_counter_is_synchronized
+  * Fix spawn when the main module is a script
+  * Allow a pool to start with zero processes
+  * Credit READY to the worker that ran the task
+  * Fix pool terminate() hang when a worker dies holding the outqueue lock
+  * Raise the task's exception from imap() iterators
+  * Reject non-positive chunksize in Pool.imap() and Pool.imap_unordered(),
+    including when Python runs with optimization enabled
+
+-------------------------------------------------------------------

Old:
----
  billiard-4.3.1.tar.gz

New:
----
  billiard-4.3.2.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-billiard.spec ++++++
--- /var/tmp/diff_new_pack.USmXg7/_old  2026-11-20 14:50:03.151826336 +0100
+++ /var/tmp/diff_new_pack.USmXg7/_new  2026-11-20 14:50:03.157826589 +0100
@@ -18,12 +18,13 @@
 
 %{?sle15_python_module_pythons}
 Name:           python-billiard
-Version:        4.3.1
+Version:        4.3.2
 Release:        0
 Summary:        Python multiprocessing fork
 License:        BSD-3-Clause
 URL:            https://github.com/celery/billiard
 Source:         
https://files.pythonhosted.org/packages/source/b/billiard/billiard-%{version}.tar.gz
+BuildRequires:  %{python_module base >= 3.10}
 BuildRequires:  %{python_module pip}
 BuildRequires:  %{python_module psutil >= 5.9.0}
 BuildRequires:  %{python_module pytest}

++++++ billiard-4.3.1.tar.gz -> billiard-4.3.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/CHANGES.txt 
new/billiard-4.3.2/CHANGES.txt
--- old/billiard-4.3.1/CHANGES.txt      2026-10-05 08:31:02.569429200 +0200
+++ new/billiard-4.3.2/CHANGES.txt      2026-11-02 10:08:24.760203000 +0100
@@ -1,3 +1,16 @@
+4.3.2 - 2026-11-02
+------------------
+- Fix flaky timeout and context availability in 
test_on_ready_counter_is_synchronized.
+- Fix spawn when the main module is a script (#470).
+- Fix AttributeError on Windows when terminating worker on hard timeout (#471).
+- Allow a pool to start with zero processes (#477).
+- Credit READY to the worker that ran the task (#474).
+- Fix pool terminate() hang when a worker dies holding the outqueue lock 
(#479).
+- Raise the task's exception from imap() iterators (#480).
+- Reject non-positive chunksize in Pool.imap() and Pool.imap_unordered(),
+  including when Python runs with optimization enabled.
+
+
 4.3.1 - 2026-10-05
 ------------------
 - Reject bool for Pool numeric args (processes, timeouts, limits) - #460
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/PKG-INFO new/billiard-4.3.2/PKG-INFO
--- old/billiard-4.3.1/PKG-INFO 2026-10-05 08:37:27.369151400 +0200
+++ new/billiard-4.3.2/PKG-INFO 2026-11-02 10:11:03.433544400 +0100
@@ -1,6 +1,6 @@
 Metadata-Version: 2.4
 Name: billiard
-Version: 4.3.1
+Version: 4.3.2
 Summary: Python multiprocessing fork with improvements and bugfixes
 Home-page: https://github.com/celery/billiard
 Author: R Oudkerk / Python Software Foundation
@@ -47,7 +47,7 @@
 
 |build-status-lin| |build-status-win| |license| |wheel| |pyversion| |pyimp|
 
-:Version: 4.3.1
+:Version: 4.3.2
 :Web: https://billiard.readthedocs.io
 :Download: https://pypi.org/project/billiard/
 :Source: https://github.com/celery/billiard/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/README.rst 
new/billiard-4.3.2/README.rst
--- old/billiard-4.3.1/README.rst       2026-10-05 08:31:02.569776300 +0200
+++ new/billiard-4.3.2/README.rst       2026-11-02 10:08:24.760441800 +0100
@@ -4,7 +4,7 @@
 
 |build-status-lin| |build-status-win| |license| |wheel| |pyversion| |pyimp|
 
-:Version: 4.3.1
+:Version: 4.3.2
 :Web: https://billiard.readthedocs.io
 :Download: https://pypi.org/project/billiard/
 :Source: https://github.com/celery/billiard/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/billiard/__init__.py 
new/billiard-4.3.2/billiard/__init__.py
--- old/billiard-4.3.1/billiard/__init__.py     2026-10-05 08:31:02.570095500 
+0200
+++ new/billiard-4.3.2/billiard/__init__.py     2026-11-02 10:08:24.760882600 
+0100
@@ -23,7 +23,7 @@
 
 from . import context
 
-__version__ = '4.3.1'
+__version__ = '4.3.2'
 __author__ = 'R Oudkerk / Python Software Foundation'
 __author_email__ = '[email protected]'
 __maintainer__ = 'Asif Saif Uddin'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/billiard/pool.py 
new/billiard-4.3.2/billiard/pool.py
--- old/billiard-4.3.1/billiard/pool.py 2026-10-05 08:12:40.525818000 +0200
+++ new/billiard-4.3.2/billiard/pool.py 2026-11-02 09:28:50.948449400 +0100
@@ -306,7 +306,12 @@
 
         if sys.platform != 'win32':
             try:
-                self.outq.put((DEATH, (pid, exitcode)))
+                # on_death's TERM_SIGNAL arriving here would leave outq locked.
+                mask = signal.pthread_sigmask(signal.SIG_BLOCK, {TERM_SIGNAL})
+                try:
+                    self.outq.put((DEATH, (pid, exitcode)))
+                finally:
+                    signal.pthread_sigmask(signal.SIG_SETMASK, mask)
                 time.sleep(1)
             finally:
                 os._exit(exitcode)
@@ -755,7 +760,7 @@
     def _trywaitkill(self, worker):
         debug('timeout: sending TERM to %s', worker._name)
         try:
-            if os.getpgid(worker.pid) == worker.pid:
+            if sys.platform != 'win32' and hasattr(os, 'getpgid') and 
hasattr(os, 'killpg') and os.getpgid(worker.pid) == worker.pid:
                 debug("worker %s is a group leader. It is safe to kill 
(SIGTERM) the whole group", worker.pid)
                 os.killpg(os.getpgid(worker.pid), signal.SIGTERM)
             else:
@@ -767,7 +772,7 @@
                 return
         debug('timeout: TERM timed-out, now sending KILL to %s', worker._name)
         try:
-            if os.getpgid(worker.pid) == worker.pid:
+            if sys.platform != 'win32' and hasattr(os, 'getpgid') and 
hasattr(os, 'killpg') and os.getpgid(worker.pid) == worker.pid:
                 debug("worker %s is a group leader. It is safe to kill 
(SIGKILL) the whole group", worker.pid)
                 os.killpg(os.getpgid(worker.pid), signal.SIGKILL)
             else:
@@ -860,9 +865,21 @@
         putlock = self.putlock
         restart_state = self.restart_state
         on_job_ready = self.on_job_ready
+        on_ready_counters = self.on_ready_counters
+        # Which worker is running which (job, i) task, so that a READY is
+        # credited to the on_ready_counter of the worker that sent it, even
+        # when the job is already gone from the cache.
+        worker_tasks = {}
+        task_workers = {}
 
         def on_ack(job, i, time_accepted, pid, synqW_fd):
             restart_state.R = 0
+            if on_ready_counters is not None:
+                # A worker only acks a task after sending READY for its
+                # previous one, so anything still recorded for it is stale.
+                task_workers.pop(worker_tasks.pop(pid, None), None)
+                worker_tasks[pid] = (job, i)
+                task_workers[job, i] = pid
             try:
                 cache[job]._ack(i, time_accepted, pid, synqW_fd)
             except (KeyError, AttributeError):
@@ -872,18 +889,18 @@
         def on_ready(job, i, obj, inqW_fd):
             if on_job_ready is not None:
                 on_job_ready(job, i, obj, inqW_fd)
+            worker_pid = task_workers.pop((job, i), None)
+            worker_tasks.pop(worker_pid, None)
+            if on_ready_counters and worker_pid in on_ready_counters:
+                on_ready_counter = on_ready_counters[worker_pid]
+                with on_ready_counter.get_lock():
+                    on_ready_counter.value += 1
+
             try:
                 item = cache[job]
             except KeyError:
                 return
 
-            if self.on_ready_counters:
-                worker_pid = next(iter(item.worker_pids()), None)
-                if worker_pid and worker_pid in self.on_ready_counters:
-                    on_ready_counter = self.on_ready_counters[worker_pid]
-                    with on_ready_counter.get_lock():
-                        on_ready_counter.value += 1
-
             if not item.ready():
                 if putlock is not None:
                     putlock.release()
@@ -899,6 +916,12 @@
                 if get_errno(exc) != errno.ESRCH:
                     raise
 
+        def on_worker_exit(pid):
+            # A worker killed between ACK and READY (time limit, SIGKILL)
+            # never sends READY for its last task.
+            task_workers.pop(worker_tasks.pop(pid, None), None)
+        self.on_worker_exit = on_worker_exit
+
         state_handlers = self.state_handlers = {
             ACK: on_ack, READY: on_ready, DEATH: on_death
         }
@@ -1062,8 +1085,8 @@
                 raise TypeError(
                     f"{name} must be an int or float, not bool (got {value!r})"
                 )
-        if processes is not None and processes < 1:
-            raise ValueError("Number of processes must be at least 1")
+        if processes is not None and processes < 0:
+            raise ValueError("Number of processes must be at least 0")
         if maxtasksperchild is not None and (
                 not isinstance(maxtasksperchild, int) or maxtasksperchild < 1):
             raise ValueError("maxtasksperchild must be a positive int or None")
@@ -1287,6 +1310,7 @@
                 del self._pool[i]
                 del self._poolctrl[worker.pid]
                 del self._on_ready_counters[worker.pid]
+                self._result_handler.on_worker_exit(worker.pid)
         if cleaned:
             all_pids = [w.pid for w in self._pool]
             for job in list(self._cache.values()):
@@ -1498,6 +1522,10 @@
         if self._state != RUN:
             return
         lost_worker_timeout = lost_worker_timeout or self.lost_worker_timeout
+        if chunksize < 1:
+            raise ValueError(
+                'Chunksize must be 1+, not {0:n}'.format(chunksize),
+            )
         if chunksize == 1:
             result = IMapIterator(self._cache,
                                   lost_worker_timeout=lost_worker_timeout)
@@ -1508,7 +1536,6 @@
             ))
             return result
         else:
-            assert chunksize > 1
             task_batches = Pool._get_tasks(func, iterable, chunksize)
             result = IMapIterator(self._cache,
                                   lost_worker_timeout=lost_worker_timeout)
@@ -1527,6 +1554,10 @@
         if self._state != RUN:
             return
         lost_worker_timeout = lost_worker_timeout or self.lost_worker_timeout
+        if chunksize < 1:
+            raise ValueError(
+                'Chunksize must be 1+, not {0:n}'.format(chunksize),
+            )
         if chunksize == 1:
             result = IMapUnorderedIterator(
                 self._cache, lost_worker_timeout=lost_worker_timeout,
@@ -1538,7 +1569,6 @@
             ))
             return result
         else:
-            assert chunksize > 1
             task_batches = Pool._get_tasks(func, iterable, chunksize)
             result = IMapUnorderedIterator(
                 self._cache, lost_worker_timeout=lost_worker_timeout,
@@ -1748,6 +1778,9 @@
         if timeout_handler is not None:
             timeout_handler.terminate()
 
+        # A worker added during the loop below would never be terminated.
+        stop_if_not_current(worker_handler)
+
         # Terminate workers which haven't already finished
         if pool and hasattr(pool[0], 'terminate'):
             debug('terminating workers')
@@ -2044,7 +2077,7 @@
         success, value = item
         if success:
             return value
-        raise Exception(value)
+        raise value.exception
 
     __next__ = next                    # XXX
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/billiard/spawn.py 
new/billiard-4.3.2/billiard/spawn.py
--- old/billiard-4.3.1/billiard/spawn.py        2026-09-17 08:52:08.070970000 
+0200
+++ new/billiard-4.3.2/billiard/spawn.py        2026-11-02 09:16:20.806367900 
+0100
@@ -260,10 +260,7 @@
     # Figure out whether to initialise main in the subprocess as a module
     # or through direct execution (or to leave it alone entirely)
     main_module = sys.modules['__main__']
-    try:
-        main_mod_name = main_module.__spec__.name
-    except AttributeError:
-        main_mod_name = main_module.__name__
+    main_mod_name = getattr(main_module.__spec__, "name", None)
     if main_mod_name is not None:
         d['init_main_from_name'] = main_mod_name
     elif sys.platform != 'win32' or (not WINEXE and not WINSERVICE):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/billiard.egg-info/PKG-INFO 
new/billiard-4.3.2/billiard.egg-info/PKG-INFO
--- old/billiard-4.3.1/billiard.egg-info/PKG-INFO       2026-10-05 
08:37:27.336799600 +0200
+++ new/billiard-4.3.2/billiard.egg-info/PKG-INFO       2026-11-02 
10:11:03.392879200 +0100
@@ -1,6 +1,6 @@
 Metadata-Version: 2.4
 Name: billiard
-Version: 4.3.1
+Version: 4.3.2
 Summary: Python multiprocessing fork with improvements and bugfixes
 Home-page: https://github.com/celery/billiard
 Author: R Oudkerk / Python Software Foundation
@@ -47,7 +47,7 @@
 
 |build-status-lin| |build-status-win| |license| |wheel| |pyversion| |pyimp|
 
-:Version: 4.3.1
+:Version: 4.3.2
 :Web: https://billiard.readthedocs.io
 :Download: https://pypi.org/project/billiard/
 :Source: https://github.com/celery/billiard/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/t/unit/test_pool.py 
new/billiard-4.3.2/t/unit/test_pool.py
--- old/billiard-4.3.1/t/unit/test_pool.py      2026-10-05 08:12:40.527043000 
+0200
+++ new/billiard-4.3.2/t/unit/test_pool.py      2026-11-02 09:28:50.948744300 
+0100
@@ -1,6 +1,8 @@
 import os
 import signal
+import sys
 import time
+from unittest.mock import Mock
 
 import pytest
 
@@ -67,6 +69,39 @@
 
 
 class test_pool:
+    @pytest.mark.parametrize('method', ['imap', 'imap_unordered'])
+    @pytest.mark.parametrize('chunksize', [0, -1])
+    @pytest.mark.parametrize('items', [[], [1, 2]])
+    def test_imap_rejects_nonpositive_chunksize(self, method, chunksize, 
items):
+        pool = Mock(_state=billiard.pool.RUN, _cache={})
+        iterable = iter(items)
+
+        with pytest.raises(ValueError, match=r'Chunksize must be 1\+'):
+            getattr(billiard.pool.Pool, method)(
+                pool, simple_task, iterable, chunksize=chunksize,
+            )
+
+        assert list(iterable) == items
+        assert not pool._cache
+        pool._taskqueue.put.assert_not_called()
+
+    @pytest.mark.parametrize('method', ['imap', 'imap_unordered'])
+    @pytest.mark.parametrize('chunksize', [1, 2])
+    def test_imap_valid_chunksize_after_rejection(self, method, chunksize):
+        pool = Mock(_state=billiard.pool.RUN, _cache={})
+        imap = getattr(billiard.pool.Pool, method)
+        with pytest.raises(ValueError):
+            imap(pool, simple_task, [1, 2], chunksize=0)
+        result = imap(pool, simple_task, [1, 2, 3], chunksize)
+        (tasks, set_length), = pool._taskqueue.put.call_args.args
+        count = 0
+        for _, (job, index, func, args, kwargs) in tasks:
+            pool._cache[job]._set(index, (True, func(*args, **kwargs)))
+            count += 1
+        set_length(count)
+        assert sorted(result) == [2, 4, 6]
+        assert not pool._cache
+
     def test_memory_error_from_callback_propagates(self):
         def callback(value):
             raise MemoryError(value)
@@ -92,6 +127,100 @@
         # If I call to handle the timeouts I expect no exception
         next(timeout_handler.handle_timeouts())
 
+    def test_timeout_handler_trywaitkill_windows(self, monkeypatch):
+        monkeypatch.setattr(sys, "platform", "win32")
+        from unittest.mock import MagicMock
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker._popen.wait.return_value = True
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        handler._trywaitkill(worker)
+        worker.terminate.assert_called_once()
+
+    def test_timeout_handler_trywaitkill_windows_timeout_escalation(self, 
monkeypatch):
+        monkeypatch.setattr(sys, "platform", "win32")
+        from unittest.mock import MagicMock, patch
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker._popen.wait.return_value = False
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        with patch("billiard.pool._kill") as mock_kill:
+            handler._trywaitkill(worker)
+            worker.terminate.assert_called_once()
+            mock_kill.assert_called_once_with(worker.pid, 
billiard.pool.SIGKILL)
+
+    def test_timeout_handler_trywaitkill_posix_group_leader(self, monkeypatch):
+        monkeypatch.setattr(sys, "platform", "linux")
+        monkeypatch.setattr(signal, "SIGKILL", 9, raising=False)
+        monkeypatch.setattr(os, "getpgid", lambda pid: pid, raising=False)
+        from unittest.mock import MagicMock, patch
+        mock_killpg = MagicMock()
+        monkeypatch.setattr(os, "killpg", mock_killpg, raising=False)
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker._popen.wait.return_value = False
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        with patch("billiard.pool._kill") as mock_kill:
+            handler._trywaitkill(worker)
+            worker.terminate.assert_not_called()
+            mock_kill.assert_not_called()
+            assert mock_killpg.call_count == 2
+            mock_killpg.assert_any_call(12345, signal.SIGTERM)
+            mock_killpg.assert_any_call(12345, 9)
+
+    def test_timeout_handler_trywaitkill_posix_non_group_leader(self, 
monkeypatch):
+        monkeypatch.setattr(sys, "platform", "linux")
+        monkeypatch.setattr(os, "getpgid", lambda pid: pid + 100, 
raising=False)
+        from unittest.mock import MagicMock, patch
+        mock_killpg = MagicMock()
+        monkeypatch.setattr(os, "killpg", mock_killpg, raising=False)
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker._popen.wait.return_value = False
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        with patch("billiard.pool._kill") as mock_kill:
+            handler._trywaitkill(worker)
+            mock_killpg.assert_not_called()
+            worker.terminate.assert_called_once()
+            mock_kill.assert_called_once_with(worker.pid, 
billiard.pool.SIGKILL)
+
+    def test_timeout_handler_trywaitkill_missing_posix_functions(self, 
monkeypatch):
+        monkeypatch.setattr(sys, "platform", "linux")
+        monkeypatch.delattr(os, "getpgid", raising=False)
+        monkeypatch.delattr(os, "killpg", raising=False)
+        from unittest.mock import MagicMock, patch
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker._popen.wait.return_value = False
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        with patch("billiard.pool._kill") as mock_kill:
+            handler._trywaitkill(worker)
+            worker.terminate.assert_called_once()
+            mock_kill.assert_called_once_with(worker.pid, 
billiard.pool.SIGKILL)
+
+    def test_timeout_handler_trywaitkill_oserror_suppressed(self, monkeypatch):
+        from unittest.mock import MagicMock, patch
+        worker = MagicMock()
+        worker._name = "MockWorker-1"
+        worker.pid = 12345
+        worker.terminate.side_effect = OSError("Process already dead")
+        worker._popen.wait.return_value = False
+
+        handler = billiard.pool.TimeoutHandler([], {}, 0, 0)
+        with patch("billiard.pool._kill", side_effect=OSError("Process already 
dead")):
+            # Should not raise OSError
+            handler._trywaitkill(worker)
+
     def test_exception_traceback_present(self):
         pool = billiard.pool.Pool(1)
         results = [pool.apply_async(func, (i,)) for i in range(3)]
@@ -117,6 +246,22 @@
         pool.join()
         pool.terminate()
 
+    @pytest.mark.parametrize('method', ['imap', 'imap_unordered'])
+    def test_imap_raises_task_exception(self, method):
+        # One worker, so imap_unordered() yields in order too.
+        pool = billiard.pool.Pool(1)
+        try:
+            it = getattr(pool, method)(func, range(3))
+            assert it.next(timeout=10) == 0
+            assert it.next(timeout=10) == 1
+            # Used to raise a bare Exception wrapping the ExceptionInfo,
+            # unlike apply_async().get() and map().
+            with pytest.raises(ValueError):
+                it.next(timeout=10)
+        finally:
+            pool.terminate()
+            pool.join()
+
     def test_system_exit_from_task_replaces_worker(self):
         pool = billiard.pool.Pool(1)
         try:
@@ -232,13 +377,54 @@
 
     def test_on_ready_counter_is_synchronized(self):
         for ctx in ('spawn', 'fork', 'forkserver'):
+            if ctx not in billiard.get_all_start_methods():
+                continue
             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()
+            try:
+                pool.apply_async(func, (1,)).get(timeout=10)
+                on_ready_counter = pool.apply_async(get_on_ready_count, 
).get(timeout=10)
+                assert on_ready_counter == 1
+            finally:
+                pool.close()
+                pool.join()
+                pool.terminate()
+
+    def test_on_ready_counter_credits_worker_that_ran_the_task(self):
+        ctx = get_context()
+        counters = {101: ctx.Value('i'), 102: ctx.Value('i')}
+        cache = {}
+        handler = billiard.pool.ResultHandler(
+            None, None, cache, None, None, None, Mock(), None, None,
+            on_ready_counters=counters,
+        )
+        on_ack = handler.state_handlers[billiard.pool.ACK]
+        on_ready = handler.state_handlers[billiard.pool.READY]
+
+        # map() chunks of the same job run by different workers.
+        result = billiard.pool.MapResult(cache, 1, 2, None, None)
+        on_ack(result._job, 0, time.monotonic(), 101, None)
+        on_ack(result._job, 1, time.monotonic(), 102, None)
+        on_ready(result._job, 0, (True, [0]), None)
+        on_ready(result._job, 1, (True, [1]), None)
+        assert result.get(timeout=1) == [0, 1]
+        assert counters[101].value == 1
+        assert counters[102].value == 1
+
+        # A job that already left the cache, e.g. a map() that failed.
+        result = billiard.pool.ApplyResult(cache, None)
+        on_ack(result._job, None, time.monotonic(), 102, None)
+        del cache[result._job]
+        on_ready(result._job, None, (True, None), None)
+        assert counters[101].value == 1
+        assert counters[102].value == 2
+
+        # A worker killed between ACK and READY is forgotten when it exits.
+        result = billiard.pool.ApplyResult(cache, None)
+        on_ack(result._job, None, time.monotonic(), 101, None)
+        handler.on_worker_exit(101)
+        on_ready(result._job, None, (True, None), None)
+        assert counters[101].value == 1
+        assert counters[102].value == 2
 
     def test_graceful_shutdown_delivers_results(self):
         """Test that queued results are delivered during pool shutdown.
@@ -291,10 +477,19 @@
             assert result.get() == i * 2
 
 
-    def test_rejects_fewer_than_one_process(self):
-        for processes in (0, -1):
-            with pytest.raises(ValueError, match="at least 1"):
-                billiard.pool.Pool(processes=processes)
+    def test_rejects_negative_processes(self):
+        with pytest.raises(ValueError, match="at least 0"):
+            billiard.pool.Pool(processes=-1)
+
+    def test_starts_with_zero_processes_and_grows(self):
+        # Celery's --autoscale N,0 starts the pool at its minimum.
+        pool = billiard.pool.Pool(processes=0)
+        try:
+            pool.grow(1)
+            assert pool.apply_async(simple_task, (21,)).get(timeout=10) == 42
+        finally:
+            pool.terminate()
+            pool.join()
 
     def test_rejects_non_positive_maxtasksperchild(self):
         # Worker only asserted this, so it failed with a bare AssertionError,
@@ -320,3 +515,41 @@
         ):
             with pytest.raises(TypeError, match="bool"):
                 billiard.pool.Pool(**kwargs)
+
+    @skip.if_win32()
+    def test_worker_blocks_term_signal_while_reporting_death(self,
+                                                             monkeypatch):
+        blocked_during_put = []
+        worker = billiard.pool.Worker.__new__(billiard.pool.Worker)
+        worker.on_exit = None
+        worker.outq = Mock()
+        worker.outq.put.side_effect = lambda obj: blocked_during_put.append(
+            billiard.pool.TERM_SIGNAL in signal.pthread_sigmask(
+                signal.SIG_BLOCK, set()))
+        monkeypatch.setattr(billiard.pool.time, 'sleep', Mock())
+        monkeypatch.setattr(billiard.pool.os, '_exit', Mock())
+
+        worker._do_exit(1234, 0)
+
+        worker.outq.put.assert_called_once_with(
+            (billiard.pool.DEATH, (1234, 0)))
+        assert blocked_during_put == [True]
+        assert billiard.pool.TERM_SIGNAL not in signal.pthread_sigmask(
+            signal.SIG_BLOCK, set())
+
+    def test_terminate_pool_terminates_worker_added_during_shutdown(self):
+        pool = [Mock()]
+        replacement = Mock()
+        worker_handler = Mock()
+        worker_handler.stop.side_effect = (
+            lambda timeout=None: pool.append(replacement))
+        task_handler = Mock()
+        task_handler.is_alive.return_value = False
+
+        billiard.pool.Pool._terminate_pool(
+            Mock(), Mock(), Mock(), pool, worker_handler, task_handler,
+            Mock(), {}, None, (Mock(), task_handler, pool),
+        )
+
+        pool[0].terminate.assert_called_once_with()
+        replacement.terminate.assert_called_once_with()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/billiard-4.3.1/t/unit/test_spawn.py 
new/billiard-4.3.2/t/unit/test_spawn.py
--- old/billiard-4.3.1/t/unit/test_spawn.py     2026-09-17 08:52:08.073280300 
+0200
+++ new/billiard-4.3.2/t/unit/test_spawn.py     2026-11-02 09:16:20.807068000 
+0100
@@ -1,5 +1,7 @@
 import os
+import subprocess
 import sys
+import textwrap
 from billiard import get_context, Process, Queue
 from billiard.util import set_pdeathsig, get_pdeathsig
 import pytest
@@ -16,6 +18,55 @@
         p.join()
         assert p.exitcode == 0
 
+    def test_start_with_target_in_main_script(self, tmp_path):
+        """A target defined in a script run as __main__ can be unpickled.
+
+        The script's __main__ has no __spec__, so the child has to re-run it
+        by path to find the target.
+        """
+        result = run_script(tmp_path, '''
+            import sys
+            import billiard
+
+            def target():
+                print('hello from child')
+
+            if __name__ == '__main__':
+                p = billiard.get_context('spawn').Process(target=target)
+                p.start()
+                p.join()
+                sys.exit(p.exitcode)
+        ''')
+        assert result.returncode == 0, result.stderr
+        assert result.stdout == 'hello from child\n'
+
+    def test_pool_in_process_spawned_by_multiprocessing(self, tmp_path):
+        """A pool works in a process spawned by multiprocessing from a script.
+
+        That process runs the script as __mp_main__, which can't be imported
+        by name. Pool workers told to import it die and are replaced forever,
+        so the result is waited for with a timeout.
+        """
+        result = run_script(tmp_path, '''
+            import multiprocessing
+            import sys
+            import billiard
+
+            def run_pool():
+                with billiard.get_context('spawn').Pool(1) as pool:
+                    res = pool.apply_async(str.upper, ('hello from pool',))
+                    print(res.get(timeout=30))
+
+            if __name__ == '__main__':
+                ctx = multiprocessing.get_context('spawn')
+                p = ctx.Process(target=run_pool)
+                p.start()
+                p.join()
+                sys.exit(p.exitcode)
+        ''')
+        assert result.returncode == 0, result.stderr
+        assert result.stdout == 'HELLO FROM POOL\n'
+
     @pytest.mark.skipif(not sys.platform.startswith('linux'),
                         reason='set_pdeathsig() is supported only in Linux')
     def test_set_pdeathsig(self):
@@ -65,3 +116,12 @@
 def task_from_process(name):
     print('proc:', name)
 
+def run_script(tmp_path, source):
+    """Run *source* as a script file, so that it is the parent's __main__."""
+    script = tmp_path / 'script.py'
+    script.write_text(textwrap.dedent(source))
+    return subprocess.run(
+        [sys.executable, str(script)],
+        capture_output=True, text=True, timeout=120,
+    )
+

Reply via email to