graceful sigint
This commit is contained in:
parent
801f9eb1f7
commit
c760bf2fb3
|
@ -3,6 +3,7 @@ import asyncio
|
|||
import contextlib
|
||||
import errno
|
||||
import re
|
||||
import signal
|
||||
import sys
|
||||
import termios
|
||||
import tty
|
||||
|
@ -124,8 +125,14 @@ async def megacom(tty: str, baud: int, mode: str, logfile: Optional[str]) -> Non
|
|||
|
||||
loop = asyncio.get_event_loop()
|
||||
keycodes = KeycodeHandler()
|
||||
return await megacom_main(stdin, stdout, tty, baud, bytesize, parity, stopbits, loop, keycodes,
|
||||
log)
|
||||
|
||||
loop.add_signal_handler(signal.SIGINT, lambda: keycodes.exit_flag.set())
|
||||
|
||||
try:
|
||||
return await megacom_main(stdin, stdout, tty, baud, bytesize, parity, stopbits, loop,
|
||||
keycodes, log)
|
||||
finally:
|
||||
loop.remove_signal_handler(signal.SIGINT)
|
||||
|
||||
|
||||
async def megacom_main(stdin: asyncio.StreamReader, stdout: asyncio.StreamWriter, tty: str,
|
||||
|
|
Loading…
Reference in New Issue