Python, pass a variable by name to a Thread?

Up vote 0 down vote favorite share g+ share fb share tw.

Say that I have a function that looks like: def _thread_function(arg1, arg2=None, arg3=None): #Random code Now I want to create a thread using that function, and giving it arg2 but not arg3. I'm trying to this as below: #Note: in this code block I have already set a variable called arg1 and a variable called arg2 threading. Thread(target=self.

_thread_function, args=(arg1, arg2=arg2), name="thread_function").start() The above code gives me a syntax error. How do I fix it so that I can pass an argument to the thread as arg2? Python multithreading syntax syntax-error python-multithreading link|improve this question asked Aug 1 '11 at 21:08Dylan817 46% accept rate.

Use the kwargs parameter: threading. Thread(target=self. _thread_function, args=(arg1,), kwargs={'arg2':arg2}, name=thread_function).start().

Oh, thanks, that seemed to do it. – Dylan Aug 1 '11 at 21:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions