0

My Python app runs on Windows and OS X/macOS successfully... on Ubuntu, however, I get a Tcl_AsyncDelete error!

I know how threading works in Python with Tk, and that Tk should only be accessed from the main thread, but when my logic thread tries to open a URL with urllib.urlopen, the error apepars and Python panics. Once I remove the urlopen call to test it, the program does not crash. Happens on both, Python 2 and Python 3.

Here is the code for my project:

https://pastebin.com/Si6gNfDZ

I tried everything I could, setting logging level to DEBUG (in my code), debugging the app with pdb... No useful information.

It’s not a problem of Tk being accessed from a separate thread, or running within a thread – Tk runs within the main thread, and all communication with the logic thread happens through a shared queue...

Or maybe I am missing something? Thanks in advance!

algrithmic
  • 41
  • 7
  • Possible duplicate of [Tcl\_AsyncDelete Error Multithreading Python](https://stackoverflow.com/questions/27073762/tcl-asyncdelete-error-multithreading-python) – kostix Sep 26 '17 at 17:30
  • [This trivial search query](https://www.google.com/search?q=Tcl_AsyncDelete+error) finds both a previous question (and an answer) on SO and a number of other discussions of this problem on other resources. Have you done at least a minimum research before posting? – kostix Sep 26 '17 at 17:32
  • @kostix Well yeah, I did do my research... that’s the reason that I’m stating that Tk should be called only from the main thread! I said that, to my knowledge, no such calling of Tk from a thread takes place, and the only thing that runs threaded is the “logic thread”, writing data to a shared queue from which the GUI mainloop reads in the main thread... – algrithmic Sep 26 '17 at 20:20
  • 1
    @algrithmic Whatever you are doing with urllib, it's pushing some GUI activity onto a different thread. Tk uses thread-local state a lot inside itself (to avoid having horrible big global locks) so you need to get the threading right. Use [`threading.current_thread()`](http://docs.python.org/library/threading.html#threading.current_thread) to diagnose where you're on an unexpected thread… – Donal Fellows Sep 27 '17 at 08:35
  • @DonalFellows Thank you so much! I did check with `threading.current_thread().name`, and the issue was that `get_IP_data()` ran in `Thread-1` and not `MainThread`, because the function was called from within `Thread-1`, even though it resided outside the thread itself (just the way Python works)... The solution was to simply call `get_IP_data()` in `MainThread`. What confuses me, though, is why `urllib` interferes with `Ttkinter` anyways? But that's besides the point, issue solved. I would upvote if I could! – algrithmic Sep 28 '17 at 23:15

1 Answers1

0

The issue was that get_IP_data() ran in Thread-1 and not MainThread, because the function was called from within Thread-1, even though it resided outside the thread itself (just the way Python works)...

The solution was to simply call get_IP_data() in MainThread. What confuses me, though, is why urllib interferes with Ttkinter anyways? But that's besides the point, issue solved.

algrithmic
  • 41
  • 7