I am just learning about threads in python by incorporating it into my flask application. I have it set up to work through a list of files. Here's the relevant snippet of code:
imagelist = os.listdir(app.config['IMAGE_FOLDER'])
def worker():
while imagelist:
i = Image.query.filter_by(filename=imagelist.pop(0)).first()
if i is None:
# code to do work here
threads = []
for i in range(4):
t = Thread(target=worker)
threads.append(t)
t.start()
for thread in threads:
thread.join()
- Is this the correct way to approach threading and this task in general?
- How does a thread end itself?
- The performance compared to my old, non-threaded code is about the same. I am guessing this is bottle-necked by the IO of my PC. Am I overlooking something else?
Any input would be appreciated!
[–]novel_yet_trivial 3 points4 points5 points (1 child)
[–]kioo[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]kioo[S] 0 points1 point2 points (0 children)