6

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) TypeError: threadedCommand() takes exactly 1 argument (56 given)

2
  • 1
    if threaded is True is utterly pointless, fragile and verbose. Just use if threaded. Commented Sep 12, 2011 at 19:12
  • it comes a string though Commented Sep 12, 2011 at 19:13

1 Answer 1

22

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

thread = Thread(target=threadedCommand, args=(cmd,))
#                                                ^
Sign up to request clarification or add additional context in comments.

1 Comment

wonderful, Thanks a lot, that clears it out! appreciate your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.