如何知道反应堆状态(运行与否)?
我试过了(从谷歌搜索):
from twisted.internet import reactor if reactor.callWhenRunning(lambda: None) is not None: # do some work它的工作,但这似乎很奇怪的方式。
还有什么可以做到这一点的其他方式?
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 workIt worked, but this seems like weird way.
What can be other ways of doing this ?
最满意答案
你没有说明你正在使用哪个反应堆,但是这个页面说ReactorBase是反应堆的基类。
同样在同一页面上,它提到了一个实例变量的running , 这里会进一步解释。
它说
running =从启动 期间到关闭 期间为true的bool,其余时间为False。
有了这些信息,我们可以将您的代码更改为:
if reactor.running: # do some workYou 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更多推荐
发布评论