From b2c2002c404b437c5782682208471f07185ac58c Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 9 Apr 2020 12:27:13 +0300 Subject: [PATCH] Create dev task manually when constructing the Task --- trains/backend_interface/task/log.py | 6 +++--- trains/logger.py | 9 +++++---- trains/task.py | 9 ++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/trains/backend_interface/task/log.py b/trains/backend_interface/task/log.py index 428c8b13..de4cbf0b 100644 --- a/trains/backend_interface/task/log.py +++ b/trains/backend_interface/task/log.py @@ -168,15 +168,15 @@ class TaskHandler(BufferingHandler): def _send_events(self, a_request): try: if self._thread_pool is None: - self.__log_stderr('Warning: trains.Task - ' + self.__log_stderr('WARNING: trains.Task - ' 'Task.close() flushing remaining logs ({})'.format(self._pending)) self._pending -= 1 res = self.session.send(a_request) if not res.ok(): - self.__log_stderr("Warning: trains.log._send_events: failed logging task to backend " + self.__log_stderr("WARNING: trains.log._send_events: failed logging task to backend " "({:d} lines, {})".format(len(a_request.requests), str(res.meta))) except Exception as ex: - self.__log_stderr("Warning: trains.log._send_events: Retrying, " + self.__log_stderr("WARNING: trains.log._send_events: Retrying, " "failed logging task to backend ({:d} lines): {}".format(len(a_request.requests), ex)) # we should push ourselves back into the thread pool if self._thread_pool: diff --git a/trains/logger.py b/trains/logger.py index c6b8d2c5..a50435a9 100644 --- a/trains/logger.py +++ b/trains/logger.py @@ -724,10 +724,11 @@ class Logger(object): def _start_task_if_needed(self): # do not refresh the task status read from cached variable _status - if str(self._task._status) == str(tasks.TaskStatusEnum.created): - self._task.mark_started() - - self._task._dev_mode_task_start() + # if str(self._task._status) == str(tasks.TaskStatusEnum.created): + # self._task.mark_started() + # + # self._task._dev_mode_task_start() + pass def _flush_stdout_handler(self): if self._task_handler and DevWorker.report_stdout: diff --git a/trains/task.py b/trains/task.py index 6011ff81..8bf6279a 100644 --- a/trains/task.py +++ b/trains/task.py @@ -767,10 +767,13 @@ class Task(_Task): Close the current Task. Enables to manually shutdown the task. Should only be called if you are absolutely sure there is no need for the Task. """ + # store is main before we call at_exit, because will will Null it + is_main = self.is_main_task() self._at_exit() - self._at_exit_called = False + # leave _at_exit_called set to True (I think) + ## self._at_exit_called = False # unregister atexit callbacks and signal hooks, if we are the main task - if self.is_main_task(): + if is_main: self.__register_at_exit(None) def register_artifact(self, name, artifact, metadata=None, uniqueness_columns=True): @@ -1419,7 +1422,7 @@ class Task(_Task): parent.terminate() def _dev_mode_setup_worker(self, model_updated=False): - if running_remotely() or not self.is_main_task(): + if running_remotely() or not self.is_main_task() or self._at_exit_called: return if self._dev_worker: