Skip to content

Commit

Permalink
cli TERM handling: Stop more gracefully
Browse files Browse the repository at this point in the history
The loop.stop resulted in exceptions showing about a loop closed before
the future completed.
  • Loading branch information
chrysn committed Jul 27, 2018
1 parent bbfe33e commit e1723b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion aiocoap/util/cli.py
Expand Up @@ -54,7 +54,10 @@ def sync_main(cls, *args, **kwargs):
# exiting in case of a daemon setup, or to any other process
# management.
logging.info("Application ready.")
loop.add_signal_handler(signal.SIGTERM, loop.stop)
# Common options are 143 or 0
# (<https://github.com/go-task/task/issues/75#issuecomment-339466142> and
# <https://unix.stackexchange.com/questions/10231/when-does-the-system-send-a-sigterm-to-a-process>)
loop.add_signal_handler(signal.SIGTERM, lambda: main.__exitcode.set_result(143))
exitcode = loop.run_until_complete(main.__exitcode)
except KeyboardInterrupt:
logging.info("Keyboard interupt received, shutting down")
Expand Down
4 changes: 2 additions & 2 deletions contrib/oscore-plugtest/plugtest-client
Expand Up @@ -81,10 +81,10 @@ class PlugtestClientProgram:
print("That's not a number.")
continue
else:
if as_int - next_testno in (0, 1):
if as_int - next_testno + delta in (0, 1):
# Don't jump around randomly if user jumped around,
# but otherwise do something sane
delta = as_int - next_testno
delta = as_int - next_testno + delta
next_testno = as_int
break

Expand Down

0 comments on commit e1723b6

Please sign in to comment.