comparison py/tempserver.py @ 217:5eb7e2400c18

fix pid locking
author Matt Johnston <matt@ucc.asn.au>
date Fri, 19 Dec 2014 21:39:01 +0800
parents 2affbaae408b
children 16a83e2c97a0
comparison
equal deleted inserted replaced
215:4d82099d1fe0 217:5eb7e2400c18
108 heredir = os.path.abspath(os.path.dirname(__file__)) 108 heredir = os.path.abspath(os.path.dirname(__file__))
109 pidpath = os.path.join(heredir, 'tempserver.pid') 109 pidpath = os.path.join(heredir, 'tempserver.pid')
110 pidf = lockfile.pidlockfile.PIDLockFile(pidpath, threaded=False) 110 pidf = lockfile.pidlockfile.PIDLockFile(pidpath, threaded=False)
111 do_hup = '--hup' in sys.argv 111 do_hup = '--hup' in sys.argv
112 try: 112 try:
113 pidf.acquire(0) 113 pidf.acquire(1)
114 pidf.release() 114 pidf.release()
115 except lockfile.AlreadyLocked, e: 115 except (lockfile.AlreadyLocked, lockfile.LockTimeout), e:
116 pid = pidf.read_pid() 116 pid = pidf.read_pid()
117 if do_hup: 117 if do_hup:
118 try: 118 try:
119 os.kill(pid, signal.SIGHUP) 119 os.kill(pid, signal.SIGHUP)
120 print>>sys.stderr, "Sent SIGHUP to process %d" % pid 120 print>>sys.stderr, "Sent SIGHUP to process %d" % pid