Reputation: 138
For some reason, the folowing error is being thrown even though the one required argument is given.
Traceback (most recent call last):
File "C:\Users\josep_000\Desktop\test.py", line 53, in <module>
a=threading.Thread(target=getin(),args=(aa))
TypeError: getin() missing 1 required positional argument: 'var'
Upvotes: 1
Views: 1028
Reputation: 1209
Python threading.Thread accepts callable
object as a target.
So when you do this threading.Thread(target=getin(),args=(aa))
.. Ideally you are passing passing the return value of getin
being called with no arguments. Since getin
requires 1 argument this is an error.
You should pass like below...
threading.Thread(target=getin,args=(aa, ))
Also, Thread
class accepts tuple
as args
...
When you use parentheses
without any comma inside Python
just yields
the value given inside....If you need a tuple with one value you've to add a comma
inside.
Parentheses without any comma inside gives you a tuple object
with empty items like below..
>>> a = ()
>>> a
()
>>> type(a)
<type 'tuple'>
If you use parentheses
having one value inside without any comma
you'll endup getting like below..
>>> b = (1)
>>> type(b)
<type 'int'>
If you need a tuple having one value you've to add a comma
inside..like below.
>>> c = (1,)
>>> type(c)
<type 'tuple'>
Upvotes: 4
Reputation: 500475
Remove the parentheses after getin()
:
a=threading.Thread(target=getin(),args=(aa))
^^ these need to be removed
Currently, your code calls getin()
directly instead of passing it to the Thread
constructor to be called from the context of the new thread.
Also, args
needs to be a tuple. To create a single-element tuple, add a comma after aa
:
a = threading.Thread(target=getin, args=(aa,))
Upvotes: 4