Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pf = PrePickled(f)
pargs = [PrePickled(arg) for arg in args]
pkwargs = {k: PrePickled(v) for k, v in kwargs.items()}
for ident in _idents:
future = self.client.send_apply_request(
self._socket, pf, pargs, pkwargs,
track=track, ident=ident)
futures.append(future)
if track:
trackers = [_.tracker for _ in futures]
else:
trackers = []
if isinstance(targets, int):
futures = futures[0]
ar = AsyncResult(self.client, futures, fname=getname(f), targets=_targets, owner=True)
if block:
try:
return ar.get()
except KeyboardInterrupt:
pass
return ar
_raw_text('[output:%i]' % eid)
for output in outputs:
self._republish_displaypub(output, eid)
# finally, add execute_result:
for eid,r,execute_result in zip(targets, results, execute_results):
if execute_result is not None:
display(r)
else:
raise ValueError("groupby must be one of 'type', 'engine', 'collate', not %r" % groupby)
class AsyncMapResult(AsyncResult):
"""Class for representing results of non-blocking gathers.
This will properly reconstruct the gather.
This class is iterable at any time, and will wait on results as they come.
If ordered=False, then the first results to arrive will come first, otherwise
results will be yielded in the order they were submitted.
"""
def __init__(self, client, children, mapObject, fname='', ordered=True):
self._mapObject = mapObject
self.ordered = ordered
AsyncResult.__init__(self, client, children, fname=fname)
self._single_result = False
the code string to be executed
block : bool
whether or not to wait until done to return
default: self.block
"""
block = self.block if block is None else block
targets = self.targets if targets is None else targets
_idents, _targets = self.client._build_targets(targets)
futures = []
for ident in _idents:
future = self.client.send_execute_request(self._socket, code, silent=silent, ident=ident)
futures.append(future)
if isinstance(targets, int):
futures = futures[0]
ar = AsyncResult(self.client, futures, fname='execute', targets=_targets, owner=True)
if block:
try:
ar.get()
ar.wait_for_output()
except KeyboardInterrupt:
pass
return ar
if targets is None:
idents = []
else:
idents = self.client._build_targets(targets)[0]
# ensure *not* bytes
idents = [ ident.decode() for ident in idents ]
after = self._render_dependency(after)
follow = self._render_dependency(follow)
metadata = dict(after=after, follow=follow, timeout=timeout, targets=idents, retries=retries)
future = self.client.send_apply_request(self._socket, f, args, kwargs, track=track,
metadata=metadata)
ar = AsyncResult(self.client, future, fname=getname(f),
targets=None, owner=True,
)
if block:
try:
return ar.get()
except KeyboardInterrupt:
pass
return ar
def _render_dependency(self, dep):
"""helper for building jsonable dependencies from various input forms."""
if isinstance(dep, Dependency):
return dep.as_dict()
elif isinstance(dep, AsyncResult):
return dep.msg_ids
elif dep is None:
return []
else:
# pass to Dependency constructor
return list(Dependency(dep))
msg_ids.append(job)
elif isinstance(job, AsyncResult):
if job._children:
futures.extend(job._children)
else:
msg_ids.extend(job.msg_ids)
else:
raise TypeError("Expected msg_id, int, or AsyncResult, got %r" % job)
if msg_ids:
if single:
msg_ids = msg_ids[0]
return AsyncHubResult(self, msg_ids, owner=owner)
else:
if single and futures:
futures = futures[0]
return AsyncResult(self, futures, owner=owner)
def __init__(self, client, children, mapObject, fname='', ordered=True):
self._mapObject = mapObject
self.ordered = ordered
AsyncResult.__init__(self, client, children, fname=fname)
self._single_result = False