From 5e19fdc66b1f2a164abd6113d00e1b8dd205c0b2 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 1 Jun 2014 17:56:41 +0800 Subject: [PATCH] refine exiting --- shadowsocks/local.py | 3 ++- shadowsocks/server.py | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/shadowsocks/local.py b/shadowsocks/local.py index 6d70a12..24d3645 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -54,7 +54,8 @@ def main(): tcprelay.TCPRelay(config, True).start() while sys.stdin.read(): pass - except KeyboardInterrupt: + except (KeyboardInterrupt, IOError, OSError) as e: + logging.error(e) os._exit(0) if __name__ == '__main__': diff --git a/shadowsocks/server.py b/shadowsocks/server.py index a0b6dd7..7991dd8 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -62,14 +62,15 @@ def main(): udp_servers.append(udp_server) def run_server(): - for tcp_server in tcp_servers: - tcp_server.start() - for udp_server in udp_servers: - udp_server.start() try: + for tcp_server in tcp_servers: + tcp_server.start() + for udp_server in udp_servers: + udp_server.start() while sys.stdin.read(): pass - except KeyboardInterrupt: + except (KeyboardInterrupt, IOError, OSError) as e: + logging.error(e) os._exit(0) if int(config['workers']) > 1: @@ -86,7 +87,7 @@ def main(): else: children.append(r) if not is_child: - def handler(signum, frame): + def handler(signum, _): for pid in children: os.kill(pid, signum) os.waitpid(pid, 0)