阅读http://bugs.python.org/msg160297,我可以看到Stephen White编写的一个简单脚本,演示了Python线程在遇到此异常时的错误。
Exception AttributeError: AttributeError("'_DummyThread' object has no attribute '_Thread__block'",) in <module 'threading'
给出 Stephen White 的源代码(http://bugs.python.org/file25511/bad-thread.py),
import os
import thread
import threading
import time
def t():
threading.currentThread() # Populate threading._active with a DummyThread
time.sleep(3)
thread.start_new_thread(t, ())
time.sleep(1)
pid = os.fork()
if pid == 0:
os._exit(0)
os.waitpid(pid, 0)
我们该如何重写它以解决这个错误?
time.sleep(3)
。我认为你应该明确说明重写后的程序实际要做什么。 - Janne Karila