Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know reactor is running or not in python?

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 ?

like image 837
Patrick Avatar asked Dec 12 '22 05:12

Patrick


1 Answers

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
like image 87
Tim Avatar answered Dec 15 '22 00:12

Tim