Reputation: 3
I am trying to create multiple threads, add them to a list, go through that list and join
each one like this:
threads = []
for i in range(0, 4):
new_thread = threading.Thread(target=Runnable())
new_thread.start()
threads.append(new_thread)
for thread in threads:
print("in thread")
print(thread)
thread.join()
print("after join")
It will print "In thread" and the thread, but it never prints "after join" and because of that all of my code after does not run. Runnable()
is a function I created, which also prints what it should so I'm not sure if that code has anything to do with it.
Upvotes: 0
Views: 961
Reputation: 123463
You're calling Runnable
as you create each Thread
instance, so the thread's target
function is whatever it returns (possibly None
). Try using:
new_thread = threading.Thread(target=Runnable)
Which has target=Runnable
instead of target=Runnable()
.
Upvotes: 2