Created
October 21, 2011 10:49
-
-
Save musically-ut/1303556 to your computer and use it in GitHub Desktop.
Dealing with kill commands from the outside world
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'p' is the Popen object for the subprocess | |
all_is_well = True | |
while True: | |
try: | |
(r, w, e) = zmq.select( | |
[in_hb, in_cmd], [], [], timeout=end_time - time.time()) | |
for sock in r: | |
msg = sock.recv() | |
if sock == in_cmd: | |
print '[monitor] Order to execute' | |
all_is_well = False | |
retcode = 'Killed by order' | |
except zmq.ZMQError as e: | |
print '[monitor] *** ZMQ had a problem: ' + str(e) | |
if not all_is_well: | |
if not _kill(p): | |
print '[monitor] Probably already dead.' | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment