graceful sigint
This commit is contained in:
parent
801f9eb1f7
commit
c760bf2fb3
|
@ -3,6 +3,7 @@ import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import errno
|
import errno
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import termios
|
import termios
|
||||||
import tty
|
import tty
|
||||||
|
@ -124,8 +125,14 @@ async def megacom(tty: str, baud: int, mode: str, logfile: Optional[str]) -> Non
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
keycodes = KeycodeHandler()
|
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,
|
async def megacom_main(stdin: asyncio.StreamReader, stdout: asyncio.StreamWriter, tty: str,
|
||||||
|
|
Loading…
Reference in New Issue