0

I have a simple program that resizes a batch of images in python:

def resize(image_path_list):
    # open image
    # resize image
    # rename image
    # save new image

I'm attempting to increase the processing speed via multithreading - which was chosen over multiprocessing because A) this is an imported process (from a gui) so multiProcessing under __main__ == name wasn't an option and B) I figured opening and closing the file from disk was my optimization opportunity.

However utilizing the following thread instantiation I gained no speed increase (64.1 vs 64.05s) - I was expecting to halve it:

t1 = threading.Thread(target=resize(first_half_of_list))
t2 = threading.Thread(target=resize(second_half_of_list))

t1.start()
t2.start()
t1.join()
t2.join()

I'm testing on a batch of 150+ 1mB+ images, Any thoughts?

Adam
  • 1
  • 1
  • https://stackoverflow.com/a/10177530/4954037 – hiro protagonist May 01 '18 at 15:18
  • This answer uses multiprocessing which I can't use here because it is inside a module imported by a gui. multiprocessing outside __main__ = name just sinks into an infinate loop. – Adam May 01 '18 at 15:26
  • the answer also explains that because of the GIL (supposing the library you use does not release the GIL) you will not be able to speed up stuff just like that. – hiro protagonist May 01 '18 at 15:40
  • @hir""However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously."" - directly from 17.1 threading in the docs. Am I incorrect in my assumption that file opening, reading, and saving is not an IO operation? – Adam May 01 '18 at 19:09
  • Most of your execution takes place in resizing, I would presume. – wizzwizz4 Jul 16 '22 at 10:53

0 Answers0