Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _info_for_commandclass(type_):
from celery.worker.control import Panel
return [
(name, info)
for name, info in items(Panel.meta)
if info.type == type_
]
def utf8dict(d, encoding='utf-8'):
return {k.decode(encoding) if isinstance(k, bytes) else k: v
for k, v in items(d)}
def close(self, poller):
for f, fd in items(self.filemap):
if fd is not None:
poller.unregister(fd)
with ignore_errno('EBADF'): # pragma: no cover
os.close(fd)
self.filemap.clear()
self.fdmap.clear()
def update(self, other):
# type: (Iterable) -> None
"""Update this set from other LimitedSet, dict or iterable."""
if not other:
return
if isinstance(other, LimitedSet):
self._data.update(other._data)
self._refresh_heap()
self.purge()
elif isinstance(other, dict):
# revokes are sent as a dict
for key, inserted in items(other):
if isinstance(inserted, (tuple, list)):
# in case someone uses ._data directly for sending update
inserted = inserted[0]
if not isinstance(inserted, float):
raise ValueError(
'Expecting float timestamp, got type '
'{0!r} with value: {1}'.format(
type(inserted), inserted))
self.add(key, inserted)
else:
# XXX AVOID THIS, it could keep old data if more parties
# exchange them all over and over again
for obj in other:
self.add(obj)
def update_writers(self, writers):
[self.add_writer(*x) for x in items(writers)]
def start(self, c):
info('mingle: searching for neighbors')
I = c.app.control.inspect(timeout=1.0, connection=c.connection)
replies = I.hello(c.hostname, revoked._data) or {}
replies.pop(c.hostname, None)
if replies:
info('mingle: sync with %s nodes',
len([reply for reply, value in items(replies) if value]))
for reply in values(replies):
if reply:
try:
other_clock, other_revoked = MINGLE_GET_FIELDS(reply)
except KeyError: # reply from pre-3.1 worker
pass
else:
c.app.clock.adjust(other_clock)
revoked.update(other_revoked)
info('mingle: sync complete')
else:
info('mingle: all alone')
def workers(self):
return [hostname for hostname, w in items(self.state.workers)
if w.alive]
def _choices_by_group(cls, app):
from celery.worker.control import Panel
# need to import task modules for custom user-remote control commands.
app.loader.import_default_modules()
return {
name: info for name, info in items(Panel.meta)
if info.type == cls.control_group and info.visible
}
def update_strategies(self):
loader = self.app.loader
for name, task in items(self.app.tasks):
self.strategies[name] = task.start_strategy(self.app, self)
task.__trace__ = build_tracer(name, task, loader, self.hostname,
app=self.app)
def Namespace(__old__=None, **options):
if __old__ is not None:
for key, opt in items(options):
if not opt.old:
opt.old = {o.format(key) for o in __old__}
return options