comparison py/tempserver.py @ 529:5201f441bf4a

run 2to3
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Apr 2015 23:59:16 +0800
parents 61e61de49a50
children e39ed85d87a5
comparison
equal deleted inserted replaced
528:61e61de49a50 529:5201f441bf4a
127 except (lockfile.AlreadyLocked, lockfile.LockTimeout) as e: 127 except (lockfile.AlreadyLocked, lockfile.LockTimeout) as e:
128 pid = pidf.read_pid() 128 pid = pidf.read_pid()
129 if do_hup: 129 if do_hup:
130 try: 130 try:
131 os.kill(pid, signal.SIGHUP) 131 os.kill(pid, signal.SIGHUP)
132 print>>sys.stderr, "Sent SIGHUP to process %d" % pid 132 print("Sent SIGHUP to process %d" % pid, file=sys.stderr)
133 sys.exit(0) 133 sys.exit(0)
134 except OSError: 134 except OSError:
135 print>>sys.stderr, "Process %d isn't running?" % pid 135 print("Process %d isn't running?" % pid, file=sys.stderr)
136 sys.exit(1) 136 sys.exit(1)
137 137
138 print>>sys.stderr, "Locked by PID %d" % pid 138 print("Locked by PID %d" % pid, file=sys.stderr)
139 139
140 stale = False 140 stale = False
141 if pid > 0: 141 if pid > 0:
142 if '--new' in sys.argv: 142 if '--new' in sys.argv:
143 try: 143 try:
144 os.kill(pid, 0) 144 os.kill(pid, 0)
145 except OSError: 145 except OSError:
146 stale = True 146 stale = True
147 147
148 if not stale: 148 if not stale:
149 print>>sys.stderr, "Stopping old tempserver pid %d" % pid 149 print("Stopping old tempserver pid %d" % pid, file=sys.stderr)
150 os.kill(pid, signal.SIGTERM) 150 os.kill(pid, signal.SIGTERM)
151 time.sleep(2) 151 time.sleep(2)
152 pidf.acquire(0) 152 pidf.acquire(0)
153 pidf.release() 153 pidf.release()
154 else: 154 else:
159 except OSError: 159 except OSError:
160 stale = True 160 stale = True
161 161
162 if stale: 162 if stale:
163 # isn't still running, steal the lock 163 # isn't still running, steal the lock
164 print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) 164 print("Unlinking stale lockfile %s for pid %d" % (pidpath, pid), file=sys.stderr)
165 pidf.break_lock() 165 pidf.break_lock()
166 166
167 if do_hup: 167 if do_hup:
168 print>>sys.stderr, "Doesn't seem to be running" 168 print("Doesn't seem to be running", file=sys.stderr)
169 sys.exit(1) 169 sys.exit(1)
170 170
171 if '--daemon' in sys.argv: 171 if '--daemon' in sys.argv:
172 logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log') 172 logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log')
173 logf = open(logpath, 'a+') 173 logf = open(logpath, 'a+')