alejandroautalan / pygubu

A simple GUI builder for the python tkinter module
MIT License
2.01k stars 213 forks source link

Weird Threadpool error #260

Closed LalFX closed 2 years ago

LalFX commented 2 years ago

Hi,

This is not a pygubu error per se - but a really weird error that I could not figure out. I have a piece of code that was working fine till recently.

It is a small batch image resizing program using Pillow.

The ThreadPool part of the code has not changed but recently it fails every time with my full processor (24) count. If I reduce the number of threads to 12-13, it completes the task. More than that it errors out with a bootstrap error.

However, if I compile the code (I have been using Nuitka) - I have no issues with the compiled exe file. It resizes any number of files without issues. I have been scratching my head for a few days now without any ideas in spite of trying everything. I would really appreciate any help you can suggest.

The problem code is below; (Apologies - I am new to github and could not figure out how to get the code looking formatted)

    exts = ['jpeg', 'jpg', 'png', 'gif', 'ico', 'tif', 'tiff','tga', 'bmp', 'webp', 'wmf']
    rawfileimgs = listdir(inpath)
    fixfileimages = self.fixlist(rawfileimgs, exts)
    fcount = len(fixfileimages)

    start = perf_counter()

    if not path.exists(outpath):
        makedirs(outpath)

    # run_process()
    core = int(self.v_cpu.get())
    prog_step = 100 / fcount
    count = 0

    with ThreadPoolExecutor(max_workers = core) as t:

        # Main image processing loop with multi-threading
        futures = [t.submit(self.resize_img, imgs, res_opt) for imgs in fixfileimages]

        # Keep alive loop to update gui with file conversion info
        for fut in as_completed(futures):
            count += 1
            newprog = count * prog_step
            shwlbl = 'Processing: {}/{} files'.format(count, fcount)
            self.v_prog.set(shwlbl)
            self.v_progbar.set(newprog)
            self.mainwindow.update()

the full code is here

The UI looks like this: image

LalFX commented 2 years ago

Just to update the issue I was facing. The problem has been sorted - in case anyone else comes up on the same issue. I uninstalled the 32bit Python I was using of late (trying to solve the pygubu-designer issue) and installed a 64bit version.

When I did that, I noticed that Pillow and Pygubu had to be re-installed. Once that was complete - the code works again.

I have no idea why that worked or why the issue happened in the first place or why the compiled file worked. I do appreciate any suggestions if anyone can tell me what I was doing wrong in the first place.