我遇到Python线程问题并在参数中发送字符串.
def processLine(line) :
print "hello";
return;
Run Code Online (Sandbox Code Playgroud)
.
dRecieved = connFile.readline();
processThread = threading.Thread(target=processLine, args=(dRecieved));
processThread.start();
Run Code Online (Sandbox Code Playgroud)
其中dRecieved是连接读取的一行字符串.它调用一个简单的函数,到目前为止只有一个打印"hello"的工作.
但是我收到以下错误
Traceback (most recent call last):
File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "C:\Python25\lib\threading.py", line 446, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: processLine() takes exactly 1 arguments (232 given)
Run Code Online (Sandbox Code Playgroud)
232是我试图传递的字符串的长度,所以我猜它会将其分解为每个字符并尝试传递这样的参数.如果我只是正常调用函数,它工作正常,但我真的想将它设置为一个单独的线程.