# HG changeset patch # User Matt Johnston # Date 1393942349 -28800 # Node ID be579bcf3c7f04446e15c8596707012f3fd01035 # Parent 3f187baa3439b313a2ddf5eefc992bc6ee7a99a7 Add --new flag diff -r 3f187baa3439 -r be579bcf3c7f py/tempserver.py --- a/py/tempserver.py Tue Mar 04 22:01:25 2014 +0800 +++ b/py/tempserver.py Tue Mar 04 22:12:29 2014 +0800 @@ -3,6 +3,8 @@ import sys import os import logging +import time +import signal import gevent import gevent.monkey @@ -112,15 +114,32 @@ except lockfile.AlreadyLocked, e: pid = pidf.read_pid() print>>sys.stderr, "Locked by PID %d" % pid + stale = False if pid > 0: - try: - os.kill(pid, 0) - # must still be running PID - raise e - except OSError: - # isn't still running, steal the lock - print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) - pidf.break_lock() + if '--new' in sys.argv: + try: + os.kill(pid, 0) + except OSError: + stale = True + + if not stale: + print>>sys.stderr, "Stopping old tempserver pid %d" % pid + os.kill(pid, signal.SIGTERM) + time.sleep(2) + pidf.acquire(0) + pidf.release() + else: + try: + os.kill(pid, 0) + # must still be running PID + raise e + except OSError: + stale = True + + if stale: + # isn't still running, steal the lock + print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) + pidf.break_lock() if '--daemon' in sys.argv: logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log')