Changeset 1759
- Timestamp:
- 10/19/07 13:18:50
- Files:
-
- trunk/cherrypy/restsrv/plugins.py (modified) (7 diffs)
- trunk/cherrypy/restsrv/wspbus.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/restsrv/plugins.py
r1757 r1759 90 90 _signal.signal(signum, self._handle_signal) 91 91 if listener is not None: 92 self.bus.log("Listening for %s." % signame) 92 93 self.bus.subscribe(signame, listener) 93 94 94 95 def _handle_signal(self, signum=None, frame=None): 95 96 """Python signal handler (self.set_handler subscribes it for you).""" 96 self.bus.publish(self.signals[signum]) 97 signame = self.signals[signum] 98 self.bus.log("Caught signal %s." % signame) 99 self.bus.publish(signame) 97 100 98 101 … … 200 203 else: 201 204 # This is the first parent. Exit, now that we've forked. 205 self.bus.log('Forking once.') 202 206 sys.exit(0) 203 207 except OSError, exc: … … 212 216 pid = os.fork() 213 217 if pid > 0: 218 self.bus.log('Forking twice.') 214 219 sys.exit(0) # Exit second parent 215 220 except OSError, exc: … … 243 248 244 249 def start(self): 245 open(self.pidfile, "wb").write(str(os.getpid())) 250 pid = os.getpid() 251 open(self.pidfile, "wb").write(str(pid)) 252 self.bus.log('PID %r written to %r.' % (pid, self.pidfile)) 246 253 start.priority = 70 247 254 … … 249 256 try: 250 257 os.remove(self.pidfile) 258 self.bus.log('PID file removed: %r.' % self.pidfile) 251 259 except (KeyboardInterrupt, SystemExit): 252 260 raise … … 285 293 """Start our callback in its own perpetual timer thread.""" 286 294 if self.frequency > 0: 295 threadname = "restsrv %s" % self.__class__.__name__ 287 296 self.thread = PerpetualTimer(self.frequency, self.callback) 288 self.thread.setName( "restsrv %s" % self.__class__.__name__)297 self.thread.setName(threadname) 289 298 self.thread.start() 299 self.bus.log("Started thread %r." % threadname) 290 300 291 301 def stop(self): … … 295 305 self.thread.cancel() 296 306 self.thread.join() 307 self.bus.log("Stopped thread %r." % self.thread.getName()) 297 308 self.thread = None 298 309 trunk/cherrypy/restsrv/wspbus.py
r1758 r1759 84 84 85 85 class Bus(object): 86 """Process state-machine and messenger for HTTP site deployment.""" 86 """Process state-machine and messenger for HTTP site deployment. 87 88 All listeners for a given channel are guaranteed to be called even 89 if others at the same channel fail. Each failure is logged, but 90 execution proceeds on to the next listener. The only way to stop all 91 processing from inside a listener is to raise SystemExit and stop the 92 whole server. 93 """ 87 94 88 95 states = states … … 127 134 items.sort() 128 135 for priority, listener in items: 129 # All listeners for a given channel are guaranteed to run even130 # if others at the same channel fail. We will still log the131 # failure, but proceed on to the next listener. The only way132 # to stop all processing from one of these listeners is to133 # raise SystemExit and stop the whole server.134 136 try: 135 137 output.append(listener(*args, **kwargs))

