What is wrong with this python source code?
import threading
import subprocess as sub
def ben(fil):
pr = sub.Popen(fil,stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = pr.communicate()
print output
theapp = '''blender
blender-softwaregl'''.split()
print theapp
for u in theapp:
print u
tr = threading.Thread(target=ben, args=(u))
tr.daemon = True
tr.start()
The error is :
['blender', 'blender-softwaregl']
blender
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: ben() takes exactly 1 argument (7 given)
blender-softwaregl
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: ben() takes exactly 1 argument (18 given)
This is my problem.What is this error?
TypeError: ben() takes exactly 1 argument (18 given)
The
argsargument tothreading.Threadexpects a sequence, but you’re providing a string. This is causing it to interpret each letter of the strings as an individual argument, resulting in too many arguments for your target function.You’re very close to having the right code. You just need to fix your tuple syntax by adding a trailing comma in the parenthases: