I have a database of images that need to be processed. Each image takes around a minute to process. I'm trying to make it multi-threaded. I'm having trouble entering data into the database in a worker thread. For some reason, the data isn't saved.
Here is what the code looks like.
images = Images.query.all()
images_ = []
for image in images:
images_.append(image)
pool = ThreadPool()
pool.map(dostuff, (images_))
pool.close()
pool.join()
def dostuff(image):
# do stuff
image.done = True
db.session.commit()
Any ideas what could be happening? I also tried to pass the session into dostuff(image, session) but that didn't work either. Any help is appreciated!