python暂停和恢复按钮,Python:如何暂停和恢复线程 |
您所在的位置:网站首页 › python暂停和恢复 › python暂停和恢复按钮,Python:如何暂停和恢复线程 |
我有一个装有websockets的Tornado服务器:class SockHandler(SockJSConnection): def on_open(self, request): clients.add(self) def on_message(self, message): if (message == 'start'): self.send({'message' : start_msg}) thr = threading.Thread(target=func_with_loop, args=(self.on_result,)).start() if (message == 'next'): # resume 'thr' def on_result(self, response): self.send(response) # pause 'thr' def on_error(self, e): print(e) def on_close(self): clients.remove(self) self.close() 在UI上,我有“开始”和“下一步”按钮,它们通过套接字连接发送这些消息。在 我在“start”创建一个线程,它触发一个运行有限循环的函数,并在每个循环中调用回调self.on_result。在 现在工作得很好。但是我需要做的是在两个注释处执行命令来暂停和恢复线程。在 我应该如何实现这一点? 谢谢 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |