Skip to content

Commit ade0b2a

Browse files
committed
Add unit tests
1 parent 2eeeeb6 commit ade0b2a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,22 @@ def test_forkserver_sigkill(self):
807807
if os.name != 'nt':
808808
self.check_forkserver_death(signal.SIGKILL)
809809

810+
def test_process_pickling(self):
811+
if self.TYPE == 'threads':
812+
self.skipTest(f'test not appropriate for {self.TYPE}')
813+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
814+
with self.subTest(proto=proto):
815+
proc = self.Process()
816+
proc.start()
817+
# Calling set_spawning_popen with a value other than None
818+
# allows pickling the authentication keys of processes
819+
# (.authkey), which is prevented by default in
820+
# AuthenticationString for security reasons.
821+
multiprocessing.context.set_spawning_popen(0)
822+
serialized_proc = pickle.dumps(proc, protocol=proto)
823+
deserialized_proc = pickle.loads(serialized_proc)
824+
self.assertIsInstance(deserialized_proc, self.Process)
825+
810826

811827
#
812828
#
@@ -2920,7 +2936,25 @@ def test_mymanager_context_prestarted(self):
29202936
manager.start()
29212937
with manager:
29222938
self.common(manager)
2923-
self.assertEqual(manager._process.exitcode, 0)
2939+
# bpo-30356: BaseManager._finalize_manager() sends SIGTERM
2940+
# to the manager process if it takes longer than 1 second to stop,
2941+
# which happens on slow buildbots.
2942+
self.assertIn(manager._process.exitcode, (0, -signal.SIGTERM))
2943+
2944+
def test_mymanager_pickling(self):
2945+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2946+
with self.subTest(proto=proto):
2947+
manager = MyManager()
2948+
manager.start()
2949+
# Calling set_spawning_popen with a value other than None
2950+
# allows pickling the authentication keys of processes
2951+
# (.authkey), which is prevented by default in
2952+
# AuthenticationString for security reasons.
2953+
multiprocessing.context.set_spawning_popen(0)
2954+
serialized_manager = pickle.dumps(manager, protocol=proto)
2955+
deserialized_manager = pickle.loads(serialized_manager)
2956+
self.assertIsInstance(deserialized_manager, MyManager)
2957+
manager.shutdown()
29242958

29252959
def common(self, manager):
29262960
foo = manager.Foo()

0 commit comments

Comments
 (0)