Browse Source

refine exiting

auth
clowwindy 11 years ago
parent
commit
5e19fdc66b
  1. 3
      shadowsocks/local.py
  2. 7
      shadowsocks/server.py

3
shadowsocks/local.py

@ -54,7 +54,8 @@ def main():
tcprelay.TCPRelay(config, True).start() tcprelay.TCPRelay(config, True).start()
while sys.stdin.read(): while sys.stdin.read():
pass pass
except KeyboardInterrupt: except (KeyboardInterrupt, IOError, OSError) as e:
logging.error(e)
os._exit(0) os._exit(0)
if __name__ == '__main__': if __name__ == '__main__':

7
shadowsocks/server.py

@ -62,14 +62,15 @@ def main():
udp_servers.append(udp_server) udp_servers.append(udp_server)
def run_server(): def run_server():
try:
for tcp_server in tcp_servers: for tcp_server in tcp_servers:
tcp_server.start() tcp_server.start()
for udp_server in udp_servers: for udp_server in udp_servers:
udp_server.start() udp_server.start()
try:
while sys.stdin.read(): while sys.stdin.read():
pass pass
except KeyboardInterrupt: except (KeyboardInterrupt, IOError, OSError) as e:
logging.error(e)
os._exit(0) os._exit(0)
if int(config['workers']) > 1: if int(config['workers']) > 1:
@ -86,7 +87,7 @@ def main():
else: else:
children.append(r) children.append(r)
if not is_child: if not is_child:
def handler(signum, frame): def handler(signum, _):
for pid in children: for pid in children:
os.kill(pid, signum) os.kill(pid, signum)
os.waitpid(pid, 0) os.waitpid(pid, 0)

Loading…
Cancel
Save