Skip to content

Commit 085bd35

Browse files
committed
fix respawn
1 parent a0f4f1b commit 085bd35

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

gnsq_mp/master.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from itertools import cycle
77
from collections import OrderedDict
88

9+
from gevent import subprocess, sleep, signal
910
from gnsq import Lookupd
10-
from gevent import subprocess, sleep
1111

1212
from cpu_affinity import ProcessAffinity
1313

@@ -70,18 +70,22 @@ def check_worker(self):
7070
self._procs[nsqd_tcp_addr] = proc
7171
self.poll_count += 1
7272

73+
def kill_all(self):
74+
for k, p in self._procs.iteritems():
75+
p.send_signal(2)
76+
p.wait()
77+
print>>sys.stderr, ' [kill] %s pid=%s, rc=%d' % (k, p.pid, p.returncode)
78+
7379
@classmethod
7480
def run(cls, *args, **kwargs):
7581
inst = cls(*args, **kwargs)
82+
signal(2, inst.kill_all)
7683
try:
7784
while 1:
7885
inst.check_worker()
7986
sleep(3)
8087
except KeyboardInterrupt:
81-
for k, p in inst._procs.iteritems():
82-
p.send_signal(2)
83-
p.wait()
84-
print>>sys.stderr, ' [kill] %s pid=%s, rc=%d' % (k, p.pid, p.returncode)
88+
inst.kill_all()
8589
print>>sys.stderr, ' [exit] all subprocess stopped.'
8690
exit(0)
8791
return inst

gnsq_mp/worker.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def shutdown(cls, timeout=8):
9999
# for conn in cls.reader.conns:
100100
# conn.close()
101101
# if cls.reader:
102-
spawn(cls.reader.close)
102+
if cls.reader:
103+
spawn(cls.reader.close)
103104
sleep(cls._shutdown_timer)
104105

105106

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='gnsq_mp',
8-
version="0.2.2",
8+
version="0.2.3",
99
# packages=find_packages('src'),
1010
packages=['gnsq_mp'],
1111
install_requires=[

0 commit comments

Comments
 (0)