繁体   English   中英

在Python中使用反应器进行多重处理

[英]Multi Processing in python with reactor

我有这样的代码:

from twisted.internet import task
from twisted.internet import reactor
def Fun1():
    print('No')
communicate1 = task.LoopingCall(Fun1)
communicate1.start(0.1)
reactor.run()

while True:
    print('yes')
    time.sleep(1)

它不应该同时运行Func1和while循环吗? 它出什么问题了? 它只打印编号。

反应器在单个进程和单个线程中进行多路复用。 它不会自动为您启动多个线程。

直到整个程序关闭, reactor.run()有望运行。 此后通常没有应用程序代码。

也许你要启动多个进程,但你需要使用另一个库,如concurrent.futures或者multiprocessing或扭曲的spawnProcess()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM