仅使用事件即可停止和重新启动线程
sine.threads的Python项目详细描述
示例
fromsine.threadsimport*deffunc(stop_event):while1:ifstop_event.is_set():break# do your workthread=StoppableThread(target=func)thread.start()# ...thread.stop(-1)# stop and join forever# thread.stopped() == Truethread=ReStartableThread(target=func,event_name='stop_event')# can specify the parameter's namethread.start()# ...thread.stop(1)# stop and join for 1 second# ...thread.start()# ...thread.stop()thread.join()# ...
更改日志
V0.1.712019年2月9日
- 更改为与python3一起运行
V0.1.6,2018年10月7日
- stop()变为stop(timeout=0),以便连接线程 不管它是否还活着。
- 如果未指定事件名称,则接收不严格
停止事件,它将被添加到“args”
所以它可以通过
*args'
或其他参数来接收 - 添加:螺纹锁紧
V0.1.52018-9-11
- 修正join()的逻辑,当直接join()时不带start()而带stop()
V0.1.42018-6-7
- 重新启动线程支持加入旧线程实例
- 修复:restartablethread.start总是创建新实例
- 改进注释并更改为英语
- 更改目录结构并更新setup.py
- add tests.py