Skip to content

Instantly share code, notes, and snippets.

@ionelmc
Created November 29, 2013 14:12
Show Gist options
  • Select an option

  • Save ionelmc/7706251 to your computer and use it in GitHub Desktop.

Select an option

Save ionelmc/7706251 to your computer and use it in GitHub Desktop.
join that extends and revokes
def join(resultset, task_options=(), queue_results=False, propagate=True,
interval=0.5, cleanup=None):
pending_results = deque(resultset.results)
resultset = ResultSet(list(resultset.results))
completed_results = []
def handle_abort():
logger.warning(
"task_control.join is aborting ! Revoking taskset %s and calling cleanup function %r.",
resultset,
cleanup
)
revoke(resultset)
if cleanup:
cleanup()
try:
while pending_results:
result = pending_results.popleft()
try:
resultvalue = result.wait(
timeout = interval,
propagate = propagate,
interval = interval
)
completed_results.append(resultvalue)
if queue_results and isinstance(resultvalue, list):
for maybe_signature in resultvalue:
if isinstance(maybe_signature, Signature):
newresult = maybe_signature.apply_async(
**task_options
)
pending_results.append(newresult)
resultset.results.append(newresult)
except TimeoutError:
pending_results.append(result)
check_termination(handle_abort)
except Exception:
handle_abort()
raise
return completed_results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment