question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception RuntimeError: RuntimeError('main thread is not in main loop',)

See original GitHub issue

In the main program I call modules (five times). In each module I use joblib.Parallel in the same way. If I call only one of these modules from the main program, everything is doing great. If in the main program I choose the option to execute the five modules one by one, in the third of them I get the following error:

Exception RuntimeError: RuntimeError('main thread is not in main loop',) in <bound method PhotoImage.__del__ of <Tkinter.PhotoImage instance at 0x7f72ac673c68>> ignored
Tcl_AsyncDelete: async handler deleted by the wrong thread
Aborted

When only that third subprogram (module) is called, everything is executed without error. joblib-0.13.0, Debian

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Naereencommented, Nov 20, 2018

My diagnosis seems correct, I won’t need more, I just changed back and no longer open any matplotlib plots before being completely done with the Parallel-code. It’s not worth my time trying to find a better solution. Thanks again for your reply!

2reactions
Naereencommented, Nov 20, 2018

Hi @tomMoral, thanks for the quick reply 👍!

I understood the bug (I think): if a first figure is created (but not manually deleted with del fig) before I run my Parallel(...)(delayed(...)) code, then the garbage collector can decide (pseudo)randomly to delete the figure anytime, in one of the thread. This makes the code break, because tkinter doesn’t support multi-threaded code, as soon as this garbage collector delete does not happen in the main thread (which explain why the bug happened faster on my 4-core & 4-thread machine than on another 12-core & 12-thread machine).

I’ll try again to verify if my diagnosis is correct. if it is, then I don’t think we can do anything: tkinter is known to not work in multi-threaded environment, and joblib can’t magically decide to preventively close all matplotlib figures before going into Parallel-powered code! If my diagnosis is wrong, I’ll provide a minimal working example that can be launch in a virtualenv, so you can test the bug. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: main thread is not in main loop - python
From your traceback, it looks like you're running the workerGuiThread from a thread you're creating elsewhere, rather from the main thread of ...
Read more >
[ Bug] RuntimeError: main thread is not in main loop (window ...
Finally I suspected that the issue could be related to an expired timeout from within TCL/TK. ... Tkapp_Call() calls WaitForMainloop() where there ...
Read more >
“main thread is not in main loop” in Tkinter - Python Forum
I have paths of two GIF files in a list. After input (name of the planet) it just shows looped GIF in tkinter....
Read more >
RuntimeError: main thread is not in main loop
Console shuts down after I 'import importlib' and here is the error it gives. >>> import importlib. Exception ignored in: <bound method ...
Read more >
tkthread · PyPI
The Tcl/Tk language that comes with Python follows a different threading model ... RuntimeError: main thread is not in main loop RuntimeError: Calling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found