我有这样的代码:为什么我得到这个线程错误?
import urllib2
import thread
a = 0
def workers():
while 1:
a+=1
silva = urllib2.urlopen('http://en.dilandau.eu/download_music/said-the-whale-'+str(a)+'.html')
si = silva.read()
if 'var playlist' not in si:
print a
break
thread.start_new_thread(workers,())
while 1:
print '---'
,但我得到一个错误:
Unhandled exception in thread started by <function workers at 0x0000000002B1FDD8>
有谁知道为什么我得到这个错误?
你可以添加一个try/catch块打印出细节上的未处理的异常?不相关,但我建议将'a'的定义移到'''函数定义 - 它不在线程之间共享,所以最好保存在使用它的一个线程本地。 – sarnold 2011-06-01 02:54:06