Opened 10 years ago

Closed 8 years ago

#2854 defect closed fixed (fixed)

Reactor claims not be running although reactor.run() has been called

Reported by: htj Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: therve, Jean-Paul Calderone Branch:
Author:

Description

Hi

The following code fails in current twisted trunk:

from twisted.internet import reactor, defer

def main():
    reactor.stop()
    return

if __name__ == '__main__':
    reactor.callWhenRunning(main)
    reactor.run()

The output is:

Unhandled error in Deferred:
Traceback (most recent call last):
  File "/home/htj/pack/python/twisted/internet/base.py", line 389, in _continueFiring
    callable(*args, **kwargs)
  File "ting.py", line 8, in main
    d.addBoth(lambda _ : reactor.stop())
  File "/home/htj/pack/python/twisted/internet/defer.py", line 210, in addBoth
    callbackKeywords=kw, errbackKeywords=kw)
  File "/home/htj/pack/python/twisted/internet/defer.py", line 182, in addCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "/home/htj/pack/python/twisted/internet/defer.py", line 317, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "ting.py", line 4, in main
    reactor.stop()
  File "/home/htj/pack/python/twisted/internet/base.py", line 480, in stop
    raise RuntimeError, "can't stop reactor that isn't running"
exceptions.RuntimeError: can't stop reactor that isn't running

This has worked well in previous versions if twisted. Am I doing anything wrong? If I start doing actual IO the above structure works well.

I've tracked down the change in behaviour to be in internet/base.py from changeset 20909: http://twistedmatrix.com/trac/changeset/20909

Although I do not really an idea of whats causing it.

I'm not quite sure how to have this as a trial test, it seems to be related to events during startup.

Change History (8)

comment:1 Changed 10 years ago by htj

Type: enhancementdefect

enhancement -> defect

comment:2 Changed 10 years ago by Jean-Paul Calderone

Priority: normalhigh

Apparently running used to be set to 1 after the before phase of the startup event in all cases. Now, if there are no before phase triggers for the startup event which return Deferreds which have not already been called back, running will not be set to 1 until after all before phase startup triggers have run. This includes triggers added via callWhenRunning.

I suppose the old behavior should be restored. Obviously, as part of that, tests for running should be added. Hopefully just as obviously, the exact semantics of running should probably be documented (however, I still think running is a private attribute of the reactor. It is unfortunate that it does not have an _ prefix).

This is a regression introduced by r20909. If conflicts which would make it difficult have not yet been introduced, that revision should be reverted, fixed, re-reviewed, and re-merged.

comment:3 Changed 10 years ago by Jean-Paul Calderone

Milestone: Core-2.6

comment:4 Changed 10 years ago by therve

Cc: therve Jean-Paul Calderone added

The great thing (or maybe not), is that it has been fixed in r21395. At least, the reported problem doesn't appear anymore.

comment:5 Changed 10 years ago by Jean-Paul Calderone

Some new tests should still be added

comment:6 Changed 9 years ago by therve

Milestone: twisted-8.0
Priority: highnormal

comment:7 Changed 8 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

This behavior is tested by twisted.internet.test.test_core.SystemEventTestsBuilder.test_stopWhenAlreadyStopped.

comment:8 Changed 6 years ago by <automation>

Owner: Glyph deleted
Note: See TracTickets for help on using tickets.