0

我在 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_idUnicode。_ 但是,即使我str(fsq_id)或`fsq_id.encode('utf-8'),我也会遇到同样的错误。有什么解决办法吗?

4

1 回答 1

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'))
于 2013-08-25T12:43:29.750 回答