mirror of
https://github.com/clearml/clearml
synced 2025-04-05 21:26:20 +00:00
Disconnect stdout/stderr logger on exit
This commit is contained in:
parent
de9c88bc2d
commit
5ec4d80493
@ -77,17 +77,17 @@ class StdStreamPatch(object):
|
||||
StdStreamPatch._stderr_proxy.connect(logger)
|
||||
|
||||
@staticmethod
|
||||
def remove_std_logger():
|
||||
def remove_std_logger(logger=None):
|
||||
if isinstance(sys.stdout, PrintPatchLogger):
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
sys.stdout.connect(None)
|
||||
sys.stdout.disconnect(logger)
|
||||
except Exception:
|
||||
pass
|
||||
if isinstance(sys.stderr, PrintPatchLogger):
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
sys.stderr.connect(None)
|
||||
sys.stderr.disconnect(logger)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@ -172,6 +172,11 @@ class PrintPatchLogger(object):
|
||||
self._cur_line = ''
|
||||
self._log = logger
|
||||
|
||||
def disconnect(self, logger=None):
|
||||
# disconnect the logger only if it was registered
|
||||
if not logger or self._log == logger:
|
||||
self.connect(None)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr in ['_log', '_terminal', '_log_level', '_cur_line']:
|
||||
return self.__dict__.get(attr)
|
||||
|
@ -735,6 +735,9 @@ class Logger(object):
|
||||
self._task_handler.flush()
|
||||
|
||||
def _close_stdout_handler(self, wait=True):
|
||||
# detach the sys stdout/stderr
|
||||
StdStreamPatch.remove_std_logger(self)
|
||||
|
||||
if self._task_handler and DevWorker.report_stdout:
|
||||
t = self._task_handler
|
||||
self._task_handler = None
|
||||
|
Loading…
Reference in New Issue
Block a user