Fix deferred configuration support

This commit is contained in:
allegroai 2021-09-10 13:08:03 +03:00
parent 75dfed6022
commit c046acb816
5 changed files with 20 additions and 7 deletions

View File

@ -167,7 +167,7 @@ class Reporter(InterfaceBase, AbstractContextManager, SetupUploadMixin, AsyncMan
"""
log = metrics.log.getChild('reporter')
log.setLevel(log.level)
if self.__class__.max_float_num_digits is -1:
if self.__class__.max_float_num_digits == -1:
self.__class__.max_float_num_digits = config.get('metrics.plot_max_num_digits', None)
super(Reporter, self).__init__(session=metrics.session, log=log)

View File

@ -60,10 +60,11 @@ def deferred_config(key=None, default=Config._MISSING, transform=None, multi=Non
return LazyEvalWrapper(
callback=lambda:
(ConfigSDKWrapper.get(key, default) if not multi else
next(ConfigSDKWrapper.get(*a) for a in multi if ConfigSDKWrapper.get(*a)))
next((ConfigSDKWrapper.get(*a) for a in multi if ConfigSDKWrapper.get(*a)), None))
if transform is None
else (transform() if key is None else transform(ConfigSDKWrapper.get(key, default) if not multi else # noqa
next(ConfigSDKWrapper.get(*a) for a in multi if ConfigSDKWrapper.get(*a)))))
next((ConfigSDKWrapper.get(*a) for a in multi if ConfigSDKWrapper.get(*a)), None)))
)
config_obj = ConfigWrapper

View File

@ -1050,16 +1050,18 @@ class Logger(object):
# noinspection PyProtectedMember
return self._default_upload_destination or self._task._get_default_report_storage_uri()
def flush(self):
# type: () -> bool
def flush(self, wait=False):
# type: (bool) -> bool
"""
Flush cached reports and console outputs to backend.
:param wait: Wait for all outstanding uploads and events to be sent (default False)
:return: True, if successfully flushed the cache. False, if failed.
"""
self._flush_stdout_handler()
if self._task:
return self._task.flush()
return self._task.flush(wait_for_uploads=wait)
return False
def get_flush_period(self):

View File

@ -542,7 +542,7 @@ class BackgroundMonitor(object):
return self._instances.setdefault(self._task_obj_id, [])
def _is_subprocess_mode_and_not_parent_process(self):
return self.is_subprocess_mode() and self._main_process != os.getpid()
return self.is_subprocess_mode() and self._parent_pid != os.getpid()
@classmethod
def is_subprocess_enabled(cls, task=None):

View File

@ -191,6 +191,16 @@ class WrapperBase(type):
cb = object.__getattribute__(self, "_callback")
obj = cb()
object.__setattr__(self, '_wrapped', obj)
# we have to convert the instance to the real type
if args and len(args) == 1 and (
type(args[0]) == LazyEvalWrapper or hasattr(type(args[0]), '_base_class_')):
try:
int(args[0]) # force loading the instance
except: # noqa
pass
args = (object.__getattribute__(args[0], "_wrapped"), )
mtd = getattr(obj, name)
return mtd(*args, **kwargs)
return method