@@ -154,6 +154,10 @@ class does handle all of the logic around asynchronously cleanly setting up
154154 Whether or not we should silence logging when setting up the cluster.
155155 name: str, optional
156156 A name to use when printing out the cluster, defaults to type name
157+ shutdown_on_close: bool
158+ Whether or not to close the cluster when the program exits
159+ shutdown_scheduler: bool
160+ Whether or not to shut down the scheduler when the cluster is closed
157161
158162 Examples
159163 --------
@@ -247,6 +251,7 @@ def __init__(
247251 name = None ,
248252 shutdown_on_close = True ,
249253 scheduler_sync_interval = 1 ,
254+ shutdown_scheduler = True ,
250255 ):
251256 if loop is None and asynchronous :
252257 loop = IOLoop .current ()
@@ -271,6 +276,7 @@ def __init__(
271276 self ._correct_state_waiting = None
272277 self ._name = name or type (self ).__name__
273278 self .shutdown_on_close = shutdown_on_close
279+ self .shutdown_scheduler = shutdown_scheduler
274280
275281 super ().__init__ (
276282 asynchronous = asynchronous ,
@@ -450,13 +456,14 @@ async def _close(self):
450456
451457 if self .scheduler_comm :
452458 async with self ._lock :
453- with suppress (OSError ):
454- await self .scheduler_comm .terminate ()
459+ if self .shutdown_scheduler :
460+ with suppress (OSError ):
461+ await self .scheduler_comm .terminate ()
455462 await self .scheduler_comm .close_rpc ()
456463 else :
457464 logger .warning ("Cluster closed without starting up" )
458465
459- if self .scheduler :
466+ if self .scheduler and self . shutdown_scheduler :
460467 await self .scheduler .close ()
461468 for w in self ._created :
462469 assert w .status in {
0 commit comments