[Twisted-Python] Twisted.web signal handling

Krzysztof Nowak pegazik at gmail.com
Mon Sep 26 10:40:06 EDT 2005

On 9/24/05, Jp Calderone <exarkun at divmod.com> wrote:
> Timeouts should be managed using twisted.internet.reactor.callLater().

Thanks. I am not really deep in the twisted. I just want to make this
application and that would be all (for now). I have rewrite my
previous code in this way:

def Timeout():
   raise ConnectionError

def HistosRendering:
       Event = reactor.callLater(0.0001, Timeout)	
           <Some activity that need timeout>
       except ConnectionError:
           <In case of timeout>

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

resource = Resource()

But still, it doesn't work. Timeout() is called, but exception is
making whole process to fail and the except: statestment is not even
started. I'm quite shure, that this timeouting-stuff should be some
standard problem, but I failed to find any information in the net. So
please, help me once again.

> JP Calderone:
> Also, there is a race condition between the end of your try suite and the timer.cancel() call.  The exception could be raised after the else suite is entered but before the timer is actually cancelled.

Do you have any ideas how to avoid that problem?

> >
> >class Resource(resource.Resource):
> >    def render(self, request):
> >        HistosRender()
> You are blocking the entire process for the during of the render() call.  This is another reason not to make whatever synchronous connection attempt you are making and instead use something Twisted provides.  No other activities can occur, process-wide, while your code is running.  If this is a multiuser application, *everyone* using it will experience periods of unresponsiveness when *anyone* causes blocking code to run.

If adding asynchronous approach would force me to restructure whole
project, it would stay for time just like this. This could be next
step, but timeouting is much more important to me....

Krzysztof Nowak

More information about the Twisted-Python mailing list