如何知道反应堆正在运行或不在python中?(How to know reactor is running or not in python?)

编程入门 行业动态 更新时间:2024-10-26 10:27:22
如何知道反应堆正在运行或不在python中?(How to know reactor is running or not in python?)

如何知道反应堆状态(运行与否)?

我试过了(从谷歌搜索):

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 work

It 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 work

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

更多推荐

本文发布于:2023-07-22 20:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1223303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:反应堆   正在运行   python   reactor   running

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!