I never used multithreading before so I searched an easy example and found this approach from 8 years ago that opens 10 threads and joins them later:
(I liked it because I also needed to save the results of my thread functions)
How to get the return value from a thread in python?
def foo(bar, result, index):
print 'hello {0}'.format(bar)
result[index] = "foo"
from threading import Thread
threads = [None] * 10
results = [None] * 10
for i in range(len(threads)):
threads[i] = Thread(target=foo, args=('world!', results, i))
threads[i].start()
# do some other stuff
for i in range(len(threads)):
threads[i].join()
print " ".join(results)
I managed to implemented this into my code (that I know to work correctly without multi-threading) and the implementation works: No error and it seems everything finishes and does what it should.
Just afterwards iPython hardly responds anymore (super slow) so I can't continue working. (I can hardly type and new code I enter in iPython runs super slow)
Any ideas what might cause the problem?
According to the ResourceManager the CPUs are still processing something. But why? The script has finished! At least I am 99% sure it did. I am truly thankful for any tips!