Python:如何暂停和恢复线程

时间:2017-04-05 21:40:39

标签: python multithreading

我有一个带有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

现在这种方法非常好。但我需要做的是在两条注释中执行命令以暂停和恢复线程。

我应该如何实现这一目标? 谢谢

0 个答案:

没有答案
相关问题