[Twisted-Python] threadedselectreactor - shutting down the foreign event loop

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Mon Jul 18 06:41:15 MDT 2005


(resend)

On Monday 18 July 2005 11:43, Bob Ippolito wrote:
> On Jul 17, 2005, at 11:54 PM, Toby Dickenson wrote:

> > a. Calling reactor.stop() when there is a GUI shutdown request,
> > b. Using reactor.addSystemEventTrigger to shut down the foreign  
> > event loop
> > after reactor shutdown.
> 
> This is currently the only supported and recommended way.

Thanks for that clear statement.

> It's possible, I guess, use a proxy for the waker function that uses  
> a thread lock so that you can reliably swap out the real waker at the  
> right time.  However, you must somehow acquire that lock before your  
> foreign event loop has shut down (which is of the same level of  
> invasiveness as the recommended solution!) so that it will block the  
> proxy call until a new waker is installed.  In the finally clause,  
> you'd install a new trivial waker (the apply function would work) and  
> release that lock so that any pending calls would complete.

Yes, that is much neater.

My 'trigger' waker function is already queueing requests (it is used for more 
than just twisted integration) so I dont need to replace the waker - rather 
my finally clause needs to contain a new mini event loop that continues to 
processing my queue until the reactor is fully closed. As far as 
threadedselectreactor is concerned this looks no different to my normal event 
loop.

Thanks again,

-- 
Toby Dickenson




More information about the Twisted-Python mailing list