@@ -807,6 +807,22 @@ def test_forkserver_sigkill(self):
807
807
if os .name != 'nt' :
808
808
self .check_forkserver_death (signal .SIGKILL )
809
809
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
+
810
826
811
827
#
812
828
#
@@ -2920,7 +2936,25 @@ def test_mymanager_context_prestarted(self):
2920
2936
manager .start ()
2921
2937
with manager :
2922
2938
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 ()
2924
2958
2925
2959
def common (self , manager ):
2926
2960
foo = manager .Foo ()
0 commit comments