I am generating rather large images, and so I want to thread it to render different parts of the image at once.
for startX in xrange(0, width, threadChunk):
t = Thread(target = threaded_chunk, args = (thread_num, startX, startX + threadChunk, 1, 0, height, 1))
t.start()
t.join()
print 'next thread'
thread_num += 1
However, this doesn't seem to do what I think it should --- it seems to me that it waits for one thread to finish before going onto the next one. I found this out because my actual threaded function (threaded_chunk
), has a print statement at the end, which notifies me that the thread has finished. The shell looks like this when I run the program:
Thread 1 completed
next thread
Thread 2 completed
next thread
# etc
Therefore, it is waiting for one to finish before running the next.
I am using t.join()
because I want to execute a final step after all of the threads have finished: image.save(imagepath)
.
Is there a way to run numerous threads at once but then wait until all of the threads have finished to execute a task? Thanks!
EDIT: My current method works on Ubuntu 12.04 LTS, but not Windows 8.1.