comparison py/tempserver.py @ 514:0c29d1a16c8c

fix pid locking
author Matt Johnston <matt@ucc.asn.au>
date Fri, 19 Dec 2014 21:39:01 +0800
parents 4a8a1e886a8c
children 16a83e2c97a0
comparison
equal deleted inserted replaced
513:56cdea43b366 514:0c29d1a16c8c
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