0

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!

0

1 Answer 1

1

Did you add the image to session?

def dostuff(image):
    # do stuff
    image.done = True
    db.session.add(image)
    db.session.commit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.