summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-05-03 18:45:46 (GMT)
committerGitHub <noreply@github.com>2024-05-03 18:45:46 (GMT)
commit998c3856c1e922ece806c162858dc587a1e92e02 (patch)
tree03077e946db80e7e78df5a9c3e14e6ba5ca04bcf /Lib/test
parentcb57a52a85a7845b1c017085f05a7f6d71855edc (diff)
downloadcpython-998c3856c1e922ece806c162858dc587a1e92e02.zip
cpython-998c3856c1e922ece806c162858dc587a1e92e02.tar.gz
cpython-998c3856c1e922ece806c162858dc587a1e92e02.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/_test_multiprocessing.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 5fc4181..46afdfc 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -6161,6 +6161,29 @@ class TestNamedResource(unittest.TestCase):
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