Skip to content

Commit

Permalink
remove sig handling and add todo
Browse files Browse the repository at this point in the history
  • Loading branch information
b-cooper committed Jan 24, 2020
1 parent e8ad8bc commit aebf2db
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions api/src/opentrons/hardware_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,15 @@ def _log_call_inner(*args, **kwargs):
return _log_call_inner



async def shutdown(loop, signal=None):
if signal:
mod_log.info(f"Received exit signal {signal.name}...")
mod_log.info("Cleaning up running tasks")
tasks = [t for t in asyncio.all_tasks() if t is not
asyncio.current_task()]

[task.cancel() for task in tasks]

await asyncio.gather(*tasks, return_exceptions=True)
loop.stop()

def handle_loop_exception(loop: asyncio.AbstractEventLoop, context):
msg = context.get("exception", context["message"])
mod_log.error(f"Caught exception: {msg}")
mod_log.info("Stopping module watcher...")


def use_or_initialize_loop(loop: asyncio.AbstractEventLoop):
checked_loop = loop or asyncio.get_event_loop()
signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT)

for s in signals:
checked_loop.add_signal_handler(
s, lambda s=s: asyncio.create_task(shutdown(checked_loop, signal=s)))
# TODO: BC 2020-01-24 use loop.add_signal_handler for proper cleanup
checked_loop.set_exception_handler(handle_loop_exception)
return checked_loop

Expand Down

0 comments on commit aebf2db

Please sign in to comment.