gh-104090: Add exit code to multiprocessing ResourceTracker (GH-115410)

This builds on https://github.com/python/cpython/pull/106807, which adds
a return code to ResourceTracker, to make future debugging easier.
Testing this “in situ” proved difficult, since the global ResourceTracker is
involved in test infrastructure. So, the tests here create a new instance and
feed it fake data.

---------

Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>
Co-authored-by: Yonatan Bitton <bityob@gmail.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
This commit is contained in:
Petr Viktorin 2024-02-21 13:54:57 +01:00 committed by GitHub
parent b052fa381f
commit 4a9e6497c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 94 additions and 7 deletions

View file

@ -3,6 +3,7 @@ import logging
import queue
import time
import unittest
import sys
from concurrent.futures._base import BrokenExecutor
from logging.handlers import QueueHandler
@ -109,6 +110,31 @@ create_executor_tests(globals(), InitializerMixin)
create_executor_tests(globals(), FailingInitializerMixin)
@unittest.skipIf(sys.platform == "win32", "Resource Tracker doesn't run on Windows")
class FailingInitializerResourcesTest(unittest.TestCase):
"""
Source: https://github.com/python/cpython/issues/104090
"""
def _test(self, test_class):
runner = unittest.TextTestRunner()
runner.run(test_class('test_initializer'))
# GH-104090:
# Stop resource tracker manually now, so we can verify there are not leaked resources by checking
# the process exit code
from multiprocessing.resource_tracker import _resource_tracker
_resource_tracker._stop()
self.assertEqual(_resource_tracker._exitcode, 0)
def test_spawn(self):
self._test(ProcessPoolSpawnFailingInitializerTest)
def test_forkserver(self):
self._test(ProcessPoolForkserverFailingInitializerTest)
def setUpModule():
setup_module()