# HG changeset patch # User Matt Johnston # Date 1371223966 -28800 # Node ID b096fc6d1ef4fc92317f1ae13b849741a2ca53fa # Parent 94d2bb7a366651d8cb9d718c31c4d1d78d53f425# Parent 4414bf8dddaa841bf514365aa7f85862ee6b5a5a merge diff -r 94d2bb7a3666 -r b096fc6d1ef4 py/tempserver.py --- a/py/tempserver.py Thu Apr 25 21:04:36 2013 +0800 +++ b/py/tempserver.py Fri Jun 14 23:32:46 2013 +0800 @@ -6,7 +6,7 @@ import gevent import gevent.monkey -import lockfile +import lockfile.pidlockfile import daemon import utils @@ -103,9 +103,23 @@ def main(): setup_logging() - pidpath = os.path.join(os.path.dirname(__file__), 'tempserver-lock') - pidf = lockfile.FileLock(pidpath, threaded=False) - pidf.acquire(0) + pidpath = os.path.join(os.path.dirname(__file__), 'tempserver.pid') + pidf = lockfile.pidlockfile.PIDLockFile(pidpath, threaded=False) + try: + pidf.acquire(0) + pidf.release() + except lockfile.AlreadyLocked, e: + pid = pidf.read_pid() + print>>sys.stderr, "Locked by PID %d" % pid + 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 '--daemon' in sys.argv: logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log')