阅读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)
我们将如何重写它以解决此错误?