MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / finished_tasks

Method finished_tasks

bbot/core/engine.py:633–652  ·  view source on GitHub ↗

Given a list of asyncio tasks, return the ones that are finished with an optional timeout

(self, tasks, timeout=None)

Source from the content-addressed store, hash-verified

631 return task
632
633 async def finished_tasks(self, tasks, timeout=None):
634 """
635 Given a list of asyncio tasks, return the ones that are finished with an optional timeout
636 """
637 if tasks:
638 try:
639 done, _ = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED, timeout=timeout)
640 return done
641 except BaseException as e:
642 if isinstance(e, (TimeoutError, asyncio.exceptions.TimeoutError)):
643 self.log.warning(f"{self.name}: Timeout after {timeout:,} seconds in finished_tasks({tasks})")
644 for task in list(tasks):
645 task.cancel()
646 self._await_cancelled_task(task)
647 else:
648 if not in_exception_chain(e, (KeyboardInterrupt, asyncio.CancelledError)):
649 self.log.error(f"{self.name}: Unhandled exception in finished_tasks({tasks}): {e}")
650 self.log.trace(traceback.format_exc())
651 raise
652 return set()
653
654 async def cancel_task(self, client_id):
655 parent_task = self.tasks.pop(client_id, None)

Callers 1

task_poolMethod · 0.95

Calls 7

_await_cancelled_taskMethod · 0.95
in_exception_chainFunction · 0.90
setFunction · 0.85
cancelMethod · 0.80
warningMethod · 0.45
errorMethod · 0.45
traceMethod · 0.45

Tested by

no test coverage detected