开发者

Python threads - number of arguments Error

I am executing a command in a thread for almost 25k times like

if threaded is True:
                thread = Thread(target=threadedCommand, args=(cmd))
                thread.start()
                thread.join()  

def threadedCommand(command):
    if command is None:
        print 'can\'t execute threaded command'
        sys.exit(-1)
    print 'executing - %s'%(command)
    os.system(command)  

and command is like

cp file dir

and what I see is

Traceback (most recent call last): File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib64/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) TypeError: threadedCommand() takes exactly 1 argument (52 given)

^CException in thread Thread-9377: Traceback (most recent call last): File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib64/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) TypeEr开发者_Go百科ror: threadedCommand() takes exactly 1 argument (56 given)


args must be a tuple. (cmd) is the same as cmd; you want a one-element tuple instead:

thread = Thread(target=threadedCommand, args=(cmd,))
#                                                ^
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜