Pausing a thread using threading class

后端 未结 6 1445
情歌与酒
情歌与酒 2020-12-08 07:41

I have a long process that i\'ve scheduled to run in a thread, because otherwise it will freeze the ui in my wxpython application.

I\'m using

thread         


        
6条回答
  •  不思量自难忘°
    2020-12-08 08:36

    You can use signals: http://docs.python.org/library/signal.html#signal.pause

    To avoid using signals you could use a token passing system. If you want to pause it from the main UI thread you could probably just use a Queue.Queue object to communicate with it.

    Just pop a message telling the thread the sleep for a certain amount of time onto the queue.

    Alternatively you could simply continuously push tokens onto the queue from the main UI thread. The worker should just check the queue every N seconds (0.2 or something like that). When there are no tokens to dequeue the worker thread will block. When you want it to start again just start pushing tokens on to the queue from the main thread again.

提交回复
热议问题