4

How to know reactor status (running or not) ?

I tried this(searched from google):

from twisted.internet import reactor
if reactor.callWhenRunning(lambda: None) is not None: 
    # do some work

It worked, but this seems like weird way.

What can be other ways of doing this ?

Patrick
  • 2,464
  • 3
  • 30
  • 47

1 Answers1

13

You do not state which reactor you are using, but this page says ReactorBase is the base class for Reactors.

Also on the same page, it mentions an instance variable running that is further explained here.

It says

running = A bool which is True from during startup to during shutdown and False the rest of the time.

With that information we can change your code to:

if reactor.running:
    # do some work
Tim
  • 41,901
  • 18
  • 127
  • 145