【发布时间】:2020-09-21 20:55:43
【问题描述】:
我正在制作一个在主线程中使用 tkinter 接口的程序。一旦用户单击按钮,cherrypy 服务器就会在另一个线程中启动。
...
def startServer():
class HelloWorld(object):
@cherrypy.expose
def printText(self):
print("Printing Some Text")
return {"sucess": "true"}
cherrypy.config.update({
'server.socket_host': '127.0.0.1',
'server.socket_port': 8080,
})
cherrypy.quickstart(HelloWorld(), '/', conf)
def serverExec():
t = threading.Thread(target=startServer, args=())
t.start()
root = Tk()
button = Button(top, text="Run", command=serverExec)
button.grid(row=0, column=0, columnspan=2, sticky=W + E)
root.mainloop()
我想知道当我单击“停止”按钮时如何停止 Cherrypy 线程。我不知道如何与 Cherrypy 线程通信,因为cherrypy 在循环中阻塞了它。
【问题讨论】:
-
尝试在
Stop按钮的回调中调用cherrypy.engine.exit()。
标签: python multithreading tkinter cherrypy