[Twisted-Python] Twisted.web signal handling

Krzysztof Nowak pegazik at gmail.com
Sat Sep 24 06:43:09 MDT 2005


Hello. I wrote a simple application using twisted.web. One of activity
of my program is to contacting with some other processes. I need some
timeout to perform this activity. The structure of my program looks
like this:

/////////////////////////////////////////////////////////////////////////////////////
def TimeoutHandler(pid):
    os.kill(pid, signal.SIGUSR1)

def handler():
    raise ConnectionError

signal.signal(signal.SIGUSR1, handler)
MyPID = os.getpid()

def HistosRendering:
        timer = threading.Timer(0.001, TimeoutHandler, [MyPID])
        timer.start()
        try:
            <Some activity that need timeout>
        except ConnectionError:
            <In case of timeout>
            return
        else:
            timer.cancel()

class Resource(resource.Resource):
    def render(self, request):
        HistosRender()

resource = Resource()
/////////////////////////////////////////////////////////////////////////////////////

Unfortunately, there is something wrong, cause in case of timeout I am
receiving error message, the TimeoutHandler is activated (in the Timer
thread), but handler() in the main thread is not activated.
I am using this kind of commands to start a server:
> mktap web --path /www/ --port 8081
> twistd -f web.tap
Maybe I should somehow "turn on" handling of signals?

Do you see any solution?

Thanks in advance,
Krzysztof Nowak


More information about the Twisted-Python mailing list