1

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'
2
  • Please post the code you're using. Your question will likely be closed as lacking a reproducible example otherwise. Commented Sep 22, 2015 at 15:47
  • It was answered correctly by someone, so apparently I did give enough detail. In any case, I can't share any code for this. Commented Sep 22, 2015 at 17:40

2 Answers 2

4

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'>
Sign up to request clarification or add additional context in comments.

Comments

4

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,))

Comments

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.