我正在尝试向 Python 应用程序添加多线程,因此从一些玩具示例开始:
import threading
def myfunc(arg1, arg2):
print 'In thread'
print 'args are', arg1, arg2
thread = threading.Thread(target=myfunc, args=('asdf', 'jkle'))
thread.start()
thread.join()
这很好用,但是当我尝试启动第二个线程时,我得到一个 RuntimeError :
import threading
def myfunc(arg1, arg2):
print 'In thread'
print 'args are', arg1, arg2
thread = threading.Thread(target=myfunc, args=('asdf', 'jkle'))
thread2 = threading.Thread(target=myfunc, args=('1234', '3763763é'))
thread.start()
thread2.start()
thread.join()
thread2.join()
由于其他人似乎在运行此代码时没有问题,让我补充一下,我在 Windows 7 x64 Pro 上使用 Python 2.6.3 32 位(如果重要的话)。