def test_maybe_evaluate(self): x = PromiseProxy(lambda: 30) self.assertFalse(x.__evaluated__()) self.assertEqual(maybe_evaluate(x), 30) self.assertEqual(maybe_evaluate(x), 30) self.assertEqual(maybe_evaluate(30), 30) self.assertTrue(x.__evaluated__())
def test_maybe_evaluate(self): x = PromiseProxy(lambda: 30) assert not x.__evaluated__() assert maybe_evaluate(x) == 30 assert maybe_evaluate(x) == 30 assert maybe_evaluate(30) == 30 assert x.__evaluated__()
def finalize(self): if not self.finalized: load_shared_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.pop()) self.finalized = True
def finalize(self): if not self.finalized: load_builtin_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.pop()) self.finalized = True
def finalize(self): """Finalizes the app by loading built-in tasks, and evaluating pending task decorators.""" if not self.finalized: load_builtin_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.pop()) self.finalized = True
def finalize(self): if not self.finalized: self.finalized = True load_shared_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.pop()) for task in self._tasks.itervalues(): task.bind(self)
def finalize(self): with self._finalize_mutex: if not self.finalized: self.finalized = True load_shared_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.popleft()) for task in values(self._tasks): task.bind(self)
def finalize(self, auto=False): with self._finalize_mutex: if not self.finalized: if auto and not self.autofinalize: raise RuntimeError("Contract breach: app not finalized") self.finalized = True _announce_app_finalized(self) pending = self._pending while pending: maybe_evaluate(pending.popleft()) for task in values(self._tasks): task.bind(self)
def finalize(self, auto=False): with self._finalize_mutex: if not self.finalized: if auto and not self.autofinalize: raise RuntimeError('Contract breach: app not finalized') self.finalized = True load_shared_tasks(self) pending = self._pending while pending: maybe_evaluate(pending.popleft()) for task in values(self._tasks): task.bind(self)
def _load_config(self): if isinstance(self.on_configure, Signal): self.on_configure.send(sender=self) else: # used to be a method pre 4.0 self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) self.configured = True settings = detect_settings( self.prepare_config(self.loader.conf), self._preconf, ignore_keys=self._preconf_set_by_auto, prefix=self.namespace, ) if self._conf is not None: # replace in place, as someone may have referenced app.conf, # done some changes, accessed a key, and then try to make more # changes to the reference and not the finalized value. self._conf.swap_with(settings) else: self._conf = settings # load lazy config dict initializers. pending_def = self._pending_defaults while pending_def: self._conf.add_defaults(maybe_evaluate(pending_def.popleft()())) # load lazy periodic tasks pending_beat = self._pending_periodic_tasks while pending_beat: self._add_periodic_task(*pending_beat.popleft()) self.on_after_configure.send(sender=self, source=self._conf) return self._conf
def _load_config(self): if isinstance(self.on_configure, Signal): self.on_configure.send(sender=self) else: # used to be a method pre 4.0 self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) defaults = dict(deepcopy(DEFAULTS), **self._preconf) self.configured = True s = self._conf = Settings( {}, [self.prepare_config(self.loader.conf), defaults], ) # load lazy config dict initializers. pending_def = self._pending_defaults while pending_def: s.add_defaults(maybe_evaluate(pending_def.popleft()())) # load lazy periodic tasks pending_beat = self._pending_periodic_tasks while pending_beat: self._add_periodic_task(*pending_beat.popleft()) # Settings.__setitem__ method, set Settings.change if self._preconf: for key, value in items(self._preconf): setattr(s, key, value) self.on_after_configure.send(sender=self, source=s) return s
def _load_config(self): if isinstance(self.on_configure, Signal): self.on_configure.send(sender=self) else: # used to be a method pre 3.2 self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) defaults = dict(deepcopy(DEFAULTS), **self._preconf) self.configured = True s = self._conf = Settings( {}, [self.prepare_config(self.loader.conf), defaults], ) # load lazy config dict initializers. pending_def = self._pending_defaults while pending_def: s.add_defaults(maybe_evaluate(pending_def.popleft()())) # load lazy periodic tasks pending_beat = self._pending_periodic_tasks while pending_beat: pargs, pkwargs = pending_beat.popleft() self._add_periodic_task(*pargs, **pkwargs) self.on_after_configure.send(sender=self, source=s) return s
def finalize(self, auto=False): """Finalizes the app by loading built-in tasks, and evaluating pending task decorators.""" with self._finalize_mutex: if not self.finalized: if auto and not self.autofinalize: raise RuntimeError('Contract breach: app not finalized') self.finalized = True _announce_app_finalized(self) pending = self._pending while pending: maybe_evaluate(pending.popleft()) for task in values(self._tasks): task.bind(self) self.on_after_finalize.send(sender=self)
def finalize(self, auto=False): """Finalize the app. This loads built-in tasks, evaluates pending task decorators, reads configuration, etc. """ with self._finalize_mutex: if not self.finalized: if auto and not self.autofinalize: raise RuntimeError('Contract breach: app not finalized') self.finalized = True _announce_app_finalized(self) pending = self._pending while pending: maybe_evaluate(pending.popleft()) for task in self._tasks.values(): task.bind(self) self.on_after_finalize.send(sender=self)
def _get_config(self): self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) defaults = dict(deepcopy(DEFAULTS), **self._preconf) self.configured = True s = Settings({}, [self.prepare_config(self.loader.conf), defaults]) # load lazy config dict initializers. pending = self._pending_defaults while pending: s.add_defaults(maybe_evaluate(pending.popleft()())) return s
def _get_config(self): self.on_configure() self.configured = True s = Settings({}, [self.prepare_config(self.loader.conf), deepcopy(DEFAULTS)]) # load lazy config dict initializers. pending = self._pending_defaults while pending: s.add_defaults(maybe_evaluate(pending.popleft()())) if self._preconf: for key, value in items(self._preconf): setattr(s, key, value) return s
def _get_config(self): if isinstance(self.on_configure, Signal): self.on_configure.send(sender=self) else: # used to be a method pre 3.2 self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) defaults = dict(deepcopy(DEFAULTS), **self._preconf) self.configured = True s = Settings({}, [self.prepare_config(self.loader.conf), defaults]) # load lazy config dict initializers. pending = self._pending_defaults while pending: s.add_defaults(maybe_evaluate(pending.popleft()())) self.on_after_configure.send(sender=self, source=s) return s
def _get_config(self): self.on_configure() if self._config_source: self.loader.config_from_object(self._config_source) self.configured = True s = Settings( {}, [self.prepare_config(self.loader.conf), deepcopy(DEFAULTS)]) # load lazy config dict initializers. pending = self._pending_defaults while pending: s.add_defaults(maybe_evaluate(pending.popleft()())) # preconf options must be explicitly set in the conf, and not # as defaults or they will not be pickled with the app instance. # This will cause errors when `CELERYD_FORCE_EXECV=True` as # the workers will not have a BROKER_URL, CELERY_RESULT_BACKEND, # or CELERY_IMPORTS set in the config. if self._preconf: s.update(self._preconf) return s
def test_maybe_evaluate(self): x = PromiseProxy(lambda: 30) self.assertEqual(maybe_evaluate(x), 30) self.assertEqual(maybe_evaluate(x), 30) self.assertEqual(maybe_evaluate(30), 30)