forked from M-Labs/artiq
artiq_client: handle Ctrl-C gracefully
This commit is contained in:
parent
002325be17
commit
450fe91e93
@ -22,6 +22,7 @@ from sipyco.pc_rpc import Client
|
|||||||
from sipyco.sync_struct import Subscriber
|
from sipyco.sync_struct import Subscriber
|
||||||
from sipyco.broadcast import Receiver
|
from sipyco.broadcast import Receiver
|
||||||
from sipyco import common_args, pyon
|
from sipyco import common_args, pyon
|
||||||
|
from sipyco.asyncio_tools import SignalHandler
|
||||||
|
|
||||||
from artiq.tools import (scale_from_metadata, short_format, parse_arguments,
|
from artiq.tools import (scale_from_metadata, short_format, parse_arguments,
|
||||||
parse_devarg_override)
|
parse_devarg_override)
|
||||||
@ -277,14 +278,21 @@ def _show_datasets(datasets):
|
|||||||
def _run_subscriber(host, port, subscriber):
|
def _run_subscriber(host, port, subscriber):
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
try:
|
||||||
|
signal_handler = SignalHandler()
|
||||||
|
signal_handler.setup()
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(subscriber.connect(host, port))
|
loop.run_until_complete(subscriber.connect(host, port))
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(asyncio.wait_for(subscriber.receive_task,
|
_, pending = loop.run_until_complete(asyncio.wait(
|
||||||
None))
|
[signal_handler.wait_terminate(), subscriber.receive_task],
|
||||||
print("Connection to master lost")
|
return_when=asyncio.FIRST_COMPLETED))
|
||||||
|
for task in pending:
|
||||||
|
task.cancel()
|
||||||
finally:
|
finally:
|
||||||
loop.run_until_complete(subscriber.close())
|
loop.run_until_complete(subscriber.close())
|
||||||
|
finally:
|
||||||
|
signal_handler.teardown()
|
||||||
finally:
|
finally:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user