[Twisted-Python] InstallSignalHandlers question

Itamar Shtull-Trauring twisted at itamarst.org
Thu Feb 20 17:47:58 EST 2003


On Thu, 20 Feb 2003 16:12:56 -0500
"Chris Skinner" <chris at websys.com> wrote:

>   I couldn't find any reference to methods/overrides I would need to
> implement in my Application. to actually do some processing on
> specific signals... is the flag in .run() just disabling some
> previous call to signal assigning a default handler?

Just schedule a method to run on startup, and then in that method use
the signal module as you usually would.

>   Primarily I'm looking to implement an in-process re-initialize,
> log-rotation and to catch the shutdown so I can terminate another
> process before exiting.

1. Twisted already does log rotation on signals, if you use twistd.
twistd id your friend (and no, that does not require TAPs).

2. in process re-initialize is a good use case.

3. Use the reactor's scheduling system - it lets you schedule events to
be run on shutdown.

http://twistedmatrix.com/documents/TwistedDocs/current/api/public/twisted.internet.interfaces.IReactorCore.html#addSystemEventTrigger
is the method you want.

E.g. reactor.addSystemEventTrigger('after', 'startup', myFunction) runs
myFunction after startup.

Or, as Bob Ippolito said, make an ApplicationService, and it will have
its stopService and startService methods called wwhen the application
starts and shuts down.

-- 
Itamar Shtull-Trauring    http://itamarst.org/
http://www.zoteca.com -- Python & Twisted consulting
***> Stop the war: http://unitedforpeace.org/ <***




More information about the Twisted-Python mailing list