From 3757a5dc1eda5e9efd84d5673891802853f65729 Mon Sep 17 00:00:00 2001 From: m-guberina <gubi.guberina@gmail.com> Date: Thu, 6 Feb 2025 10:59:39 +0100 Subject: [PATCH] this should fix ctrl-c not killing networking side processes not exiting in the case connections haven't been made (they wouldn't die if sitting on a socket.connect() or socket.listen() calls) --- python/ur_simple_control/networking/client.py | 5 +++++ python/ur_simple_control/networking/server.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/ur_simple_control/networking/client.py b/python/ur_simple_control/networking/client.py index 2cc4d94..a51ccea 100644 --- a/python/ur_simple_control/networking/client.py +++ b/python/ur_simple_control/networking/client.py @@ -65,6 +65,11 @@ def client_receiver(args, init_command, shm_name, lock): break except ConnectionRefusedError: time.sleep(0.005) + except KeyboardInterrupt: + s.close() + if args.debug_prints: + print("NETWORKING_CLIENT: caught KeyboardInterrupt, i'm out") + return if args.debug_prints: print("NETWORKING CLIENT_RECEIVER: connected to server") diff --git a/python/ur_simple_control/networking/server.py b/python/ur_simple_control/networking/server.py index 39e112e..dac3957 100644 --- a/python/ur_simple_control/networking/server.py +++ b/python/ur_simple_control/networking/server.py @@ -20,7 +20,13 @@ def server_sender(args, init_command, queue): s.bind(host_addr) if args.debug_prints: print("NETWORKING_SERVER: server listening on", host_addr) - s.listen() + try: + s.listen() + except KeyboardInterrupt: + s.close() + if args.debug_prints: + print("NETWORKING_CLIENT: caught KeyboardInterrupt, i'm out") + return comm_socket, comm_addr = s.accept() # we're only accepting a single connection s.close() -- GitLab