我有一个运行Twisted的应用程序,reactor.run()在启动一些其他线程(包括CherryPy Web服务器)后,在我的主线程中启动reactor .这是一个在Linux上按下Ctrl + C但在Windows上没有按下时干净关闭的程序:
from threading import Thread
from signal import signal, SIGINT
import cherrypy
from twisted.internet import reactor
from twisted.web.client import getPage
def stop(signum, frame):
cherrypy.engine.exit()
reactor.callFromThread(reactor.stop)
signal(SIGINT, stop)
class Root:
@cherrypy.expose
def index(self):
reactor.callFromThread(kickoff)
return "Hello World!"
cherrypy.server.socket_host = "0.0.0.0"
Thread(target=cherrypy.quickstart, args=[Root()]).start()
def print_page(html):
print(html)
def kickoff():
getPage("http://acpstats/account/login").addCallback(print_page)
reactor.run()
Run Code Online (Sandbox Code Playgroud)
我相信CherryPy是这里的罪魁祸首,因为这是我在没有CherryPy的情况下编写的另一个程序,当按下Ctrl + C时,它会在Linux和Windows上完全关闭:
from time import sleep
from threading import Thread
from signal import signal, SIGINT
from twisted.internet import reactor
from twisted.web.client import getPage
keep_going = …Run Code Online (Sandbox Code Playgroud) 好的,我有一个用cherrypy编写的应用程序,我想为它构建一个wxpython gui.问题是两个模块都使用闭环进行事件处理,(我假设)意味着当一个运行时另一个将被锁定.
我问了一些建议,建议我合并两个事件循环而不是使用stock entrypoints(quickloop()用于cherrypy和MainLoop()用于wx)
问题是我不知道该怎么做.任何建议将不胜感激.