@@ -404,8 +404,9 @@ def get_max_test_processes():
404404 The maximum number of test processes when using the --parallel option.
405405 """
406406 # The current implementation of the parallel test runner requires
407- # multiprocessing to start subprocesses with fork() or spawn().
408- if multiprocessing .get_start_method () not in {"fork" , "spawn" }:
407+ # multiprocessing to start subprocesses with fork(), forkserver(), or
408+ # spawn().
409+ if multiprocessing .get_start_method () not in {"fork" , "spawn" , "forkserver" }:
409410 return 1
410411 try :
411412 return int (os .environ ["DJANGO_TEST_PROCESSES" ])
@@ -450,9 +451,12 @@ def _init_worker(
450451 counter .value += 1
451452 _worker_id = counter .value
452453
453- start_method = multiprocessing .get_start_method ()
454+ is_spawn_or_forkserver = multiprocessing .get_start_method () in {
455+ "forkserver" ,
456+ "spawn" ,
457+ }
454458
455- if start_method == "spawn" :
459+ if is_spawn_or_forkserver :
456460 if process_setup and callable (process_setup ):
457461 if process_setup_args is None :
458462 process_setup_args = ()
@@ -463,7 +467,7 @@ def _init_worker(
463467 db_aliases = used_aliases if used_aliases is not None else connections
464468 for alias in db_aliases :
465469 connection = connections [alias ]
466- if start_method == "spawn" :
470+ if is_spawn_or_forkserver :
467471 # Restore initial settings in spawned processes.
468472 connection .settings_dict .update (initial_settings [alias ])
469473 if value := serialized_contents .get (alias ):
@@ -606,7 +610,7 @@ def __iter__(self):
606610 return iter (self .subsuites )
607611
608612 def initialize_suite (self ):
609- if multiprocessing .get_start_method () == " spawn" :
613+ if multiprocessing .get_start_method () in { "forkserver" , " spawn"} :
610614 self .initial_settings = {
611615 alias : connections [alias ].settings_dict for alias in connections
612616 }
0 commit comments