projects
/
python_utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
a2854e4
)
Adds a quiet option to executor shutdown.
author
Scott
<
[email protected]
>
Mon, 31 Jan 2022 18:03:43 +0000
(10:03 -0800)
committer
Scott
<
[email protected]
>
Mon, 31 Jan 2022 18:03:43 +0000
(10:03 -0800)
executors.py
patch
|
blob
|
history
diff --git
a/executors.py
b/executors.py
index 633b11b3b616cc2536ea514d274cbf2874a99282..e95ed716043b4962cd939b6d25885fd87826466a 100644
(file)
--- a/
executors.py
+++ b/
executors.py
@@
-84,10
+84,10
@@
class BaseExecutor(ABC):
pass
@abstractmethod
pass
@abstractmethod
- def shutdown(self,
wait: bool = Tru
e) -> None:
+ def shutdown(self,
*, wait: bool = True, quiet: bool = Fals
e) -> None:
pass
pass
- def shutdown_if_idle(self) -> bool:
+ def shutdown_if_idle(self
, *, quiet: bool = False
) -> bool:
"""Shutdown the executor and return True if the executor is idle
(i.e. there are no pending or active tasks). Return False
otherwise. Note: this should only be called by the launcher
"""Shutdown the executor and return True if the executor is idle
(i.e. there are no pending or active tasks). Return False
otherwise. Note: this should only be called by the launcher
@@
-95,7
+95,7
@@
class BaseExecutor(ABC):
"""
if self.task_count == 0:
"""
if self.task_count == 0:
- self.shutdown()
+ self.shutdown(
wait=True, quiet=quiet
)
return True
return False
return True
return False
@@
-155,11
+155,12
@@
class ThreadExecutor(BaseExecutor):
return result
@overrides
return result
@overrides
- def shutdown(self,
wait=Tru
e) -> None:
+ def shutdown(self,
*, wait: bool = True, quiet: bool = Fals
e) -> None:
if not self.already_shutdown:
logger.debug(f'Shutting down threadpool executor {self.title}')
if not self.already_shutdown:
logger.debug(f'Shutting down threadpool executor {self.title}')
- print(self.histogram.__repr__(label_formatter='%ds'))
self._thread_pool_executor.shutdown(wait)
self._thread_pool_executor.shutdown(wait)
+ if not quiet:
+ print(self.histogram.__repr__(label_formatter='%ds'))
self.already_shutdown = True
self.already_shutdown = True
@@
-197,11
+198,12
@@
class ProcessExecutor(BaseExecutor):
return result
@overrides
return result
@overrides
- def shutdown(self,
wait=Tru
e) -> None:
+ def shutdown(self,
*, wait: bool = True, quiet: bool = Fals
e) -> None:
if not self.already_shutdown:
logger.debug(f'Shutting down processpool executor {self.title}')
self._process_executor.shutdown(wait)
if not self.already_shutdown:
logger.debug(f'Shutting down processpool executor {self.title}')
self._process_executor.shutdown(wait)
- print(self.histogram.__repr__(label_formatter='%ds'))
+ if not quiet:
+ print(self.histogram.__repr__(label_formatter='%ds'))
self.already_shutdown = True
def __getstate__(self):
self.already_shutdown = True
def __getstate__(self):
@@
-1107,13
+1109,14
@@
class RemoteExecutor(BaseExecutor):
return self._helper_executor.submit(self.launch, bundle)
@overrides
return self._helper_executor.submit(self.launch, bundle)
@overrides
- def shutdown(self,
wait=Tru
e) -> None:
+ def shutdown(self,
*, wait: bool = True, quiet: bool = Fals
e) -> None:
if not self.already_shutdown:
logging.debug(f'Shutting down RemoteExecutor {self.title}')
self.heartbeat_stop_event.set()
self.heartbeat_thread.join()
self._helper_executor.shutdown(wait)
if not self.already_shutdown:
logging.debug(f'Shutting down RemoteExecutor {self.title}')
self.heartbeat_stop_event.set()
self.heartbeat_thread.join()
self._helper_executor.shutdown(wait)
- print(self.histogram.__repr__(label_formatter='%ds'))
+ if not quiet:
+ print(self.histogram.__repr__(label_formatter='%ds'))
self.already_shutdown = True
self.already_shutdown = True
@@
-1212,11
+1215,11
@@
class DefaultExecutors(object):
def shutdown(self) -> None:
if self.thread_executor is not None:
def shutdown(self) -> None:
if self.thread_executor is not None:
- self.thread_executor.shutdown()
+ self.thread_executor.shutdown(
wait=True, quiet=True
)
self.thread_executor = None
if self.process_executor is not None:
self.thread_executor = None
if self.process_executor is not None:
- self.process_executor.shutdown()
+ self.process_executor.shutdown(
wait=True, quiet=True
)
self.process_executor = None
if self.remote_executor is not None:
self.process_executor = None
if self.remote_executor is not None:
- self.remote_executor.shutdown()
+ self.remote_executor.shutdown(
wait=True, quiet=True
)
self.remote_executor = None
self.remote_executor = None