使用python多线程threadpool遇到"'NoneType' object has no attribute 'Empty'"的问题

代码如下:

#!/usr/bin/env python
# coding=utf8


import threadpool as tp

args = []
for i in range(1, 20):
    args.append(i)


def start(args):
    print '[+] %s' % args
    return True

pool = tp.ThreadPool(20)
reqs = tp.makeRequests(start, args)
[pool.putRequest(req) for req in reqs]
pool.wait()

执行后报错信息如下:

Exception in thread Thread-8 (most likely raised during interpreter shutdown):Exception in thread Thread-7 (most likely raised during interpreter shutdown):

省略部分信息

<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty'

解决方法:

调用dismissWorkers方法。

修改后的代码如下:

#!/usr/bin/env python
# coding=utf8


import threadpool as tp

args = []
for i in range(1, 20):
    args.append(i)


def start(args):
    print '[+] %s' % args
    return True

pool = tp.ThreadPool(20)
reqs = tp.makeRequests(start, args)
[pool.putRequest(req) for req in reqs]
pool.wait()
pool.dismissWorkers(20, do_join=True)

标签: python

添加新评论