[Twisted-Python] calling reactor.run() twice in PB app

Jean-Paul Calderone exarkun at divmod.com
Wed Feb 15 22:00:10 EST 2006


On Wed, 15 Feb 2006 19:59:48 -0500, Eric Smith <eric+twisted at trueblade.com> wrote:
>Jean-Paul Calderone wrote:
>>On Thu, 16 Feb 2006 10:27:27 +1100, Andrew Bennetts <andrew- 
>>twisted at puzzling.org> wrote:
>>>On Thu, Feb 16, 2006 at 08:17:42AM +1100, Jonathan Lange wrote:
>>>>On 2/16/06, Mike Pelletier <mike at mkp.ca> wrote:
>>>> > What you want is not supported.  If it were, Trial would be a lot 
>>>>simpler.
>>>> > There is some pressure to support it, but I think it's low-priority. 
>>>>(If I
>>>> > understand correctly.)  Perhaps you can just block the reactor by 
>>>>calling
>>>> > into your app rather than vice-versa?
>>>> >
>>>>
>>>>You understand correctly. It is not supported, Trial would be simpler
>>>>and it is never going to be supported.
>>>
>>>Never is a long time :)
>>>
>>>Last time I pestered glyph about this, I got him to agree that it should 
>>>work.
>>
>>Now we just need to find someone to implement it for all the reactors :)
>
>Well, I happen to be motivated just now.  I'm new to twisted, but I'm not 
>new to Python and I'm reasonably familiar with the style twisted uses (I've 
>written lots of IOCP code).
>
>If anyone could summarize the problem, and if you're serious about it 
>getting fixed, I could look at it.

There's no single particular problem preventing this from working.  More, 
the feature is generally not considered when making changes to an existing 
reactor or implementing a new one.  Startup and shutdown involve certain 
internal and external state changes which the existing reactors generally 
aren't care to allow to happen repeatedly.  For example, ReactorBase's 
__init__ method sets up two event triggers to run during shutdown.  One of 
these disconnects all connected sockets; the other actually causes the run() 
method to return.  Since system event triggers are removed as they are run, 
neither of these things happens the 2nd time a reactor deriving from 
ReactorBase shuts down.

Since most reactors in Twisted subclass ReactorBase, fixing problems in it 
will probably fix many of the reactors, although subclasses may introduce 
their own problems as well.  At least the IOCP reactor does not subclass it, 
though, so it will need to addressed separately.  Also, some testing strategy 
needs to be developed to ensure assumptions of a single run/stop pair don't 
creep back into the code.

Documentation and interfaces will also need to be updated, of course.

Jean-Paul




More information about the Twisted-Python mailing list