Mercurial > templog
changeset 173:964c32e9f8a2
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 14 Jun 2013 23:32:46 +0800 |
parents | 898d0cfecffd (current diff) 5821c5fab919 (diff) |
children | c49d87bb81b9 |
files | |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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')