gh-83856: Honor atexit for all multiprocessing start methods (GH-114279)

Use atexit for all multiprocessing start methods to cleanup.
See the GH-114279 PR discussion and related issue for details as to why.
This commit is contained in:
Tian Gao 2024-05-03 11:45:46 -07:00 committed by GitHub
parent cb57a52a85
commit 998c3856c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 5 deletions

View file

@ -6161,6 +6161,29 @@ def submain(): pass
self.assertFalse(err, msg=err.decode('utf-8'))
class _TestAtExit(BaseTestCase):
ALLOWED_TYPES = ('processes',)
@classmethod
def _write_file_at_exit(self, output_path):
import atexit
def exit_handler():
with open(output_path, 'w') as f:
f.write("deadbeef")
atexit.register(exit_handler)
def test_atexit(self):
# gh-83856
with os_helper.temp_dir() as temp_dir:
output_path = os.path.join(temp_dir, 'output.txt')
p = self.Process(target=self._write_file_at_exit, args=(output_path,))
p.start()
p.join()
with open(output_path) as f:
self.assertEqual(f.read(), 'deadbeef')
class MiscTestCase(unittest.TestCase):
def test__all__(self):
# Just make sure names in not_exported are excluded