7 Helper to run one or more async functions synchronously, with graceful
8 handling of SIGINT / Ctrl-C.
10 Returns the return value of the last function.
16 run
._sigint
= False # function attr to allow setting from closure
17 loop
= asyncio
.get_event_loop()
23 loop
.add_signal_handler(signal
.SIGINT
, abort
)
26 task
= loop
.create_task(step
)
27 loop
.run_until_complete(asyncio
.wait([task
], loop
=loop
))
29 raise KeyboardInterrupt()
31 raise task
.exception()
34 loop
.remove_signal_handler(signal
.SIGINT
)