Brandon Nadeau
Brandon Nadeau

Reputation: 3706

Threading error when the return function is invoked

I'm very new to threading, like an hour now, but I needed it for my code. I learned enough to use threads effectively in my situation but I'm stumped on how to get the return output from my function.

This is my thread invoke

threading.Thread(target = self.PageCollectionProcess(option) ).start()

When I try to return i get the output

TypeError: 'list' object is not callable
File "/usr/lib/python2.7/threading.py", line 524, in __bootstrap
  self.__bootstrap_inner()
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
  self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
  self.__target(*self.__args, **self.__kwargs)

Upvotes: 0

Views: 752

Answers (1)

thkang
thkang

Reputation: 11533

It seems like you are calling Thread in a wrong way:

threading.Thread(target = self.PageCollectionProcess(option) ).start()

should have been:

threading.Thread(target=self.PageCollectionProcess, args=(option,)).start()

think it of this way - in a very crude generalization, threading is a bit of lazy-loading; you tell a thread what to execute(a function and arguments for it) and the thread runs it later.

Upvotes: 1

Related Questions