gue*_*tli 11 python multithreading
我们遇到了这个错误:
http://bugs.python.org/issue1856守护程序在解释器关闭期间断言段错误.
现在我搜索一种代码来解决这个bug.
目前代码如下所示:
while True:
do_something()
time.sleep(interval)
Run Code Online (Sandbox Code Playgroud)
有没有办法在do_something()之前检查解释器是否仍然可用?
或者最好不要执行mythread.setDaemon(True)并检查主线程是否已退出?
回答自己的问题:
我现在使用这个模式:不要setDaemon(True),不要使用sleep(),使用parent_thread.join()
while True:
parent_thread.join(interval)
if not parent_thread.is_alive():
break
do_something()
Run Code Online (Sandbox Code Playgroud)
相关:http://docs.python.org/2/library/threading.html#threading.Thread.join
| 归档时间: |
|
| 查看次数: |
3958 次 |
| 最近记录: |