mirror of
https://github.com/clearml/clearml
synced 2025-03-03 10:42:00 +00:00
Clarify deferred_init
usage in Task.init()
(#855)
This commit is contained in:
parent
72d9b22e0d
commit
bf37df61aa
@ -81,6 +81,8 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
|
||||
__default_random_seed = 1337
|
||||
_random_seed = __default_random_seed
|
||||
|
||||
__nested_deferred_init_flag = type('_NestedDeferredInitFlag', (object,), {'content': {}})
|
||||
|
||||
class TaskTypes(Enum):
|
||||
def __str__(self):
|
||||
return str(self.value)
|
||||
|
@ -491,9 +491,7 @@ class Task(_Task):
|
||||
)
|
||||
)
|
||||
|
||||
# if deferred_init==0 this means this is the nested call that actually generates the Task.init
|
||||
# notice isinstance(False, int) is always True, so we have to check type (we wanted deferred_init != 0)
|
||||
if cls.__main_task is not None and (not (type(deferred_init) == int and deferred_init == 0)):
|
||||
if cls.__main_task is not None and deferred_init != cls.__nested_deferred_init_flag:
|
||||
# if this is a subprocess, regardless of what the init was called for,
|
||||
# we have to fix the main task hooks and stdout bindings
|
||||
if cls.__forked_proc_main_pid != os.getpid() and cls.__is_subprocess():
|
||||
@ -561,10 +559,9 @@ class Task(_Task):
|
||||
if not running_remotely():
|
||||
# only allow if running locally and creating the first Task
|
||||
# otherwise we ignore and perform in order
|
||||
# notice isinstance(False, int) is always True, so we have to check type (we wanted deferred_init != 0)
|
||||
if (not (type(deferred_init) == int and deferred_init == 0)) and ENV_DEFERRED_TASK_INIT.get():
|
||||
if ENV_DEFERRED_TASK_INIT.get():
|
||||
deferred_init = True
|
||||
if not is_sub_process_task_id and deferred_init:
|
||||
if not is_sub_process_task_id and deferred_init and deferred_init != cls.__nested_deferred_init_flag:
|
||||
def completed_cb(x):
|
||||
Task.__main_task = x
|
||||
|
||||
@ -584,7 +581,7 @@ class Task(_Task):
|
||||
auto_connect_frameworks=auto_connect_frameworks,
|
||||
auto_resource_monitoring=auto_resource_monitoring,
|
||||
auto_connect_streams=auto_connect_streams,
|
||||
deferred_init=0, # notice we use it as a flag to mark the nested call
|
||||
deferred_init=cls.__nested_deferred_init_flag,
|
||||
)
|
||||
is_deferred = True
|
||||
# mark as temp master
|
||||
|
Loading…
Reference in New Issue
Block a user