我在python中有一个列表,如下所示:
>>> print chunked_fsq_ids
[u'4bee84983686c9b6b794246e', u'4cbfb9f10d22ef3bc4e12c70', u'4b570230f964a520aa2228e3', u'51fd214d454ab82ac66e1211', u'4baf22eef964a5201ced3be3']
我想创建一个多线程进程:
def getter(id):
print id
for fsq_id in chunked_fsq_ids:
t = threading.Thread(target=getter, args=( fsq_id ))
t.start()
threads.append(t)
map(lambda t: t.join(), threads)
但是我收到了一个(循环的)TypeError:
Exception in thread Thread-461:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 808, in __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 761, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: getter() takes exactly 1 argument (24 given)
每个fsq_id
都是24个字符,所以就像我给出一个列表一样。
我是否在编码时遇到了一些问题,或者我错过了某些内容? fsq_id
为Unicode
。但是,即使我str(fsq_id)
或`fsq_id.encode('utf-8'),我也会遇到同样的错误。任何解决方案?
答案 0 :(得分:0)
您缺少尾随,
:
t = threading.Thread(target=getter, args=(fsq_id,))
以下解释为:
t = threading.Thread(target=getter, args=('4', 'b', 'e', 'e', '8', '4', '9', '8', '3', '6', '8', '6', 'c', '9', 'b', '6', 'b', '7', '9', '4', '2', '4', '6', 'e'))
:
t = threading.Thread(target=getter, args=('4bee84983686c9b6b794246e'))