@@ -5421,6 +5421,24 @@ def test_preload_resources(self):
5421
5421
print (err )
5422
5422
self .fail ("failed spawning forkserver or grandchild" )
5423
5423
5424
+ @unittest .skipIf (sys .platform == "win32" , "Only Spawn on windows so no risk of mixing" )
5425
+ @only_run_in_spawn_testsuite ("avoids redundant testing since we ignore the global context." )
5426
+ def test_mixed_startmethod (self ):
5427
+ # Fork-based locks cannot be used with spawned process
5428
+ for process_method in ["spawn" , "forkserver" ]:
5429
+ queue = multiprocessing .get_context ("fork" ).Queue ()
5430
+ p = multiprocessing .get_context (process_method ).Process (target = close_queue , args = (queue ,))
5431
+ with self .assertRaisesRegex (RuntimeError , "A SemLock created in a fork" ):
5432
+ p .start ()
5433
+
5434
+ # non-fork-based locks can be used with all other start methods
5435
+ for queue_method in ["spawn" , "forkserver" ]:
5436
+ for process_method in multiprocessing .get_all_start_methods ():
5437
+ queue = multiprocessing .get_context (queue_method ).Queue ()
5438
+ p = multiprocessing .get_context (process_method ).Process (target = close_queue , args = (queue ,))
5439
+ p .start ()
5440
+ p .join ()
5441
+
5424
5442
5425
5443
@unittest .skipIf (sys .platform == "win32" ,
5426
5444
"test semantics don't make sense on Windows" )
@@ -6201,9 +6219,3 @@ class SemLock(_multiprocessing.SemLock):
6201
6219
name = f'test_semlock_subclass-{ os .getpid ()} '
6202
6220
s = SemLock (1 , 0 , 10 , name , False )
6203
6221
_multiprocessing .sem_unlink (name )
6204
-
6205
- def test_semlock_mixed_context (self ):
6206
- queue = multiprocessing .get_context ("fork" ).Queue ()
6207
- p = multiprocessing .get_context ("spawn" ).Process (target = close_queue , args = (queue ,))
6208
- with self .assertRaisesRegex (RuntimeError , "A SemLock created in a fork" ):
6209
- p .start ()
0 commit comments