@@ -568,14 +568,14 @@ def security():
568
568
return tls_only_security ()
569
569
570
570
571
- def _kill_join ( proc , timeout ):
572
- proc . kill ()
573
- proc . join ( timeout )
574
- if proc . is_alive () :
575
- raise multiprocessing . TimeoutError (
576
- f"Process { proc } did not shut down within { timeout } s"
577
- )
578
- proc .close ()
571
+ def _kill_join_processes ( processes ):
572
+ # Join may hang or cause issues, so make sure all are killed first.
573
+ # Note that we don't use a timeout, but rely on the overall pytest timeout.
574
+ for proc in processes :
575
+ proc . kill ()
576
+ for proc in processes :
577
+ proc . join ( )
578
+ proc .close ()
579
579
580
580
581
581
def _close_queue (q ):
@@ -590,15 +590,13 @@ def cluster(
590
590
nanny = False ,
591
591
worker_kwargs = None ,
592
592
active_rpc_timeout = 10 ,
593
- shutdown_timeout = 20 ,
594
593
scheduler_kwargs = None ,
595
594
config = None ,
596
595
):
597
596
worker_kwargs = worker_kwargs or {}
598
597
scheduler_kwargs = scheduler_kwargs or {}
599
598
config = config or {}
600
599
601
- ws = weakref .WeakSet ()
602
600
enable_proctitle_on_children ()
603
601
604
602
with check_process_leak (check = True ), check_instances (), config_for_cluster_tests ():
@@ -608,6 +606,8 @@ def cluster(
608
606
_run_worker = run_worker
609
607
610
608
with contextlib .ExitStack () as stack :
609
+ processes = []
610
+ stack .callback (_kill_join_processes , processes )
611
611
# The scheduler queue will receive the scheduler's address
612
612
scheduler_q = get_mp_context ().Queue ()
613
613
stack .callback (_close_queue , scheduler_q )
@@ -620,9 +620,8 @@ def cluster(
620
620
kwargs = scheduler_kwargs ,
621
621
daemon = True ,
622
622
)
623
- ws .add (scheduler )
624
623
scheduler .start ()
625
- stack . callback ( _kill_join , scheduler , shutdown_timeout )
624
+ processes . append ( scheduler )
626
625
627
626
# Launch workers
628
627
workers_by_pid = {}
@@ -642,9 +641,8 @@ def cluster(
642
641
args = (q , scheduler_q , config ),
643
642
kwargs = kwargs ,
644
643
)
645
- ws .add (proc )
646
644
proc .start ()
647
- stack . callback ( _kill_join , proc , shutdown_timeout )
645
+ processes . append ( proc )
648
646
workers_by_pid [proc .pid ] = {"proc" : proc }
649
647
650
648
saddr_or_exception = scheduler_q .get ()
0 commit comments