因此,当我在服务器上收到任何连接时出现问题,它非常好,但也会给出错误输出,如下所示:
这是代码:
def worker(count, sequence):
print chr(27)+"[0;32m" + " Receive connections IP Address %s"
return
threads = list()
for i in range(1):
t = threading.Thread(target=worker, args=(i,))
threads.append(t)
t.start()
这是错误:
Exception in thread Thread-51:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: worker() takes exactly 2 arguments (1 given)
我做错了什么?
答案 0 :(得分:1)
worker
期待两个参数,但你只传递一个。向args
元组添加另一个参数,它将起作用:
t = threading.Thread(target=worker, args=(i,[])) # instead of (i,)