一个简单的例子重现这个报错:
from multiprocessing.dummy import Pool as ThreadPool import threading def work(): l = [1,2,3] pool = ThreadPool(3) pool.map(work2,l) pool.close() pool.join() if __name__ == '__main__': t = threading.Thread(target=work) t.start()
错误信息:
Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "/home/eggeek/palendar/geodata/operation/praser.py", line 7, in work pool = ThreadPool(3) File "/usr/lib/python2.7/multiprocessing/dummy/__init__.py", line 150, in Pool return ThreadPool(processes, initializer, initargs) File "/usr/lib/python2.7/multiprocessing/pool.py", line 685, in __init__ Pool.__init__(self, processes, initializer, initargs) File "/usr/lib/python2.7/multiprocessing/pool.py", line 136, in __init__ self._repopulate_pool() File "/usr/lib/python2.7/multiprocessing/pool.py", line 199, in _repopulate_pool w.start() File "/usr/lib/python2.7/multiprocessing/dummy/__init__.py", line 73, in start self._parent._children[self] = None AttributeError: 'Thread' object has no attribute '_children'
这是一个python的bug,参考 http://bugs.python.org/issue10015
可以按照里面的方法来绕过去,或者升级到python 2.7.5 或者 3.3.2
pool.map(work2,l)你这个里面的work2 没有声明,报错了,是不是代码没有上传全部
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 763, in run
File "test.py", line 7, in work
NameError: global name 'work2' is not defined