Skip to content

Commit

Permalink
Improve handling of KeyboardInterrupt in CLI applications (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
mryab authored Jun 11, 2023
1 parent 0d2614d commit 7a91d03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 8 additions & 3 deletions hivemind/hivemind_cli/run_dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ def main():
)
log_visible_maddrs(dht.get_visible_maddrs(), only_p2p=args.use_ipfs)

while True:
dht.run_coroutine(report_status, return_future=False)
time.sleep(args.refresh_period)
try:
while True:
dht.run_coroutine(report_status, return_future=False)
time.sleep(args.refresh_period)
except KeyboardInterrupt:
logger.info("Caught KeyboardInterrupt, shutting down")
finally:
dht.shutdown()


if __name__ == "__main__":
Expand Down
2 changes: 0 additions & 2 deletions hivemind/hivemind_cli/run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def main():
server.join()
except KeyboardInterrupt:
logger.info("Caught KeyboardInterrupt, shutting down")
finally:
server.shutdown()


if __name__ == "__main__":
Expand Down

0 comments on commit 7a91d03

Please sign in to comment.