bmaltais / kohya_ss

Apache License 2.0
9.75k stars 1.25k forks source link

RuntimeError: main thread is not in main loop #2507

Open djdavi opened 6 months ago

djdavi commented 6 months ago

Hi, I use Windows11 and I installed Pinokio enviroment to use easily AI apps.

Well, I'm using kohya_ss for training model, and when I set all and I'm ready for the training I get this error:

Screenshot 2024-05-19 083429

Maybe is something easy to solve but I'm going crazy and didn't find any solution.

Can someone explain me if is possible to fix it? Thank you

TimRhr commented 6 months ago

I have the same problem. I was able to solve it by making some changes to the 'kohya_ss/library/common_gui.py' file. I modified the 'output_message' function on line 97 as follows:

def output_message(msg='', title='', headless=False):
    if headless:
        log.info(msg)
    else:
        #msgbox(msg=msg, title=title)
        log.info(f"title: {title}, message: {msg}")

This should temporarily bypass the error.

EDIT (short explanation): The error "RuntimeError: main thread is not in main loop" occurs because tkinter operations, such as creating or modifying GUI elements, must be executed in the main thread of the application. In this case, the error arises because a tkinter function is being called from a background thread, which is not allowed by tkinter's threading model.

djdavi commented 6 months ago

Many thanks!

In the meantime I had solved it by uninstalling Pinokio and installing the various stand-alone versions of the AI apps used. But I wasn't very enthusiastic about this solution because for each application I had to install different versions of phyton, additional apps, creating messes in the folders, taking up many extra GBs. So I'm going to try this solution and go back to using Pinokio, I find it more organised and immediate to use a single app that contains everything I use.

Thanks