Reputation: 6342
Context: I've got a simple python script that writes a bunch of files to s3 (~70-100) every few seconds. Because its I/O bound, I wanted to thread the write process so the script performs better. I'm using threading
to build my threads.
Question: Since my threads are a) non-daemons and b) they only have 1 task to perform (write a file), if I loop over my list of threads and call .join()
will they finish their task and exit gracefully? Do I even need to call join()
here or will they just exit when they're done? I believe join() is the way to go here but since i'm very new to python, I don't know what I don't know....
Here's some simplified code for reference:
buildOutput() #calls the section below
for thread in threads:
thread.join()
time.sleep(60)
calls:
for item in out[fileRoot]:
#write individiual files
key = findKey(item, FILE_KEY)
full_key = FILE_PATH + str(key) + FILE_TYPE
t = FileWriter(item, full_key)
t.start()
threads.append(t) #global threads list for the script
where FileWriter is the class that does the writing.
Upvotes: 1
Views: 200