我有一个装有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。在

现在工作得很好。但是我需要做的是在两个注释处执行命令来暂停和恢复线程。在

我应该如何实现这一点?

谢谢

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐