Reputation: 135
I would like to understand the difference between the ways we can pass arguments to threads and if this has any effect on thread safety.
I am using python 3.7.3 and both instances of the code runs fine for me.
Example 1:
thread = threading.Thread(target=MultiHandler().handle, args=(argument))
Example 2:
thread = threading.Thread(target=MultiHandler().handle(argument))
Upvotes: 1
Views: 620
Reputation: 1
Python allows both args and kwargs in threading as arguments. And that can be used to make decisions inside a function. And it's the callable function where thread safety applies not on the arguments.
Upvotes: 0
Reputation: 92894
target
should be the callable object to be invoked, not the result of the function call,
unless your 2nd sample function returns another callable (target=MultiHandler().handle(argument)
returns ---> callable
).
Upvotes: 1