我有一个这样的代码:
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循环吗?它有什么问题?它只打印No。
发布于 2018-08-08 20:47:43
反应器在单个进程和单个线程中进行多路复用。它不会自动为您启动多个线程。
预计reactor.run()将一直运行,直到整个程序关闭。通常情况下,在此之后不会出现应用程序代码。
也许您想启动多个进程,但您需要使用另一个库,如concurrent.futures或multiprocessing或Twisted的spawnProcess()。
https://stackoverflow.com/questions/51746788
复制相似问题