From 7625de3f2fec0eb641024ce7ca70a7d31083fa23 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Wed, 13 Apr 2022 14:18:16 +0300 Subject: [PATCH] Fix forked process will not call _at_exit and flush all outstanding reports --- clearml/binding/environ_bind.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clearml/binding/environ_bind.py b/clearml/binding/environ_bind.py index 78746871..c24f9833 100644 --- a/clearml/binding/environ_bind.py +++ b/clearml/binding/environ_bind.py @@ -99,7 +99,16 @@ class PatchOsFork(object): # just make sure we flush the internal state (the at exist caught by the external signal does the rest # in theory we should not have to do any of that, but for some reason if we do not # the signal is never caught by the signal call backs, not sure why.... - sleep(0.1) + + # Since at_exist handlers do not work on forked processes, we have to manually call them here + if task: + try: + # not to worry there is a double _at_exit protection implemented inside task._at_exit() + # noinspection PyProtectedMember + task._at_exit() + except: # noqa + pass + # noinspection PyProtectedMember, PyUnresolvedReferences return os._org_exit(*a_args, **a_kwargs)