zephyr_mirror: Improve robustness when killing child processes.

(imported from commit f212b87ffb1fc814d289c14d3854fb1f2f6e2cf3)
This commit is contained in:
Tim Abbott 2012-11-19 11:46:05 -05:00
parent ce279d48ae
commit ff80f7df71

View file

@ -155,7 +155,11 @@ def maybe_restart_mirroring_script():
os.stat(os.path.join(options.root_path, "stamps", "tabbott_stamp")).st_mtime > start_time): os.stat(os.path.join(options.root_path, "stamps", "tabbott_stamp")).st_mtime > start_time):
logger.warning("") logger.warning("")
logger.warning("zephyr mirroring script has been updated; restarting...") logger.warning("zephyr mirroring script has been updated; restarting...")
try:
os.kill(child_pid, signal.SIGTERM) os.kill(child_pid, signal.SIGTERM)
except OSError:
# We don't care if the child process no longer exists, so just print the error
logging.exception("")
while True: while True:
try: try:
if bot_name == "extra_mirror.py": if bot_name == "extra_mirror.py":
@ -751,7 +755,11 @@ or specify the --api-key-file option.""" % (options.api_key_file,)))
if int(pid.strip()) != os.getpid(): if int(pid.strip()) != os.getpid():
# Another copy of zephyr_mirror.py! Kill it. # Another copy of zephyr_mirror.py! Kill it.
print "Killing duplicate zephyr_mirror process %s" % (pid,) print "Killing duplicate zephyr_mirror process %s" % (pid,)
try:
os.kill(int(pid), signal.SIGKILL) os.kill(int(pid), signal.SIGKILL)
except OSError:
# We don't care if the child process no longer exists, so just print the error
traceback.print_exc()
child_pid = os.fork() child_pid = os.fork()
if child_pid == 0: if child_pid == 0: