Author terry.reedy
Recipients Ivan.Pozdeev, gvanrossum, serhiy.storchaka, terry.reedy
Date 2018-05-03.19:43:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
From 1994 to 2017, _tkinter.c has received a steady flow of multiple revisions each year, for 333 total, by maybe 20 people including Guido.  This makes it one of the more actively maintained files and indicates the opposite of indifference and not caring.

I tested event generation from threads on my Win 10 machine.  With installed 2.7, with non-thread tcl 8.5, the process hangs as described, after 1 key event is sent and received.  So we should document "don't do that".

With installed 64-bit 3.6 with thread-compiled tcl 8.6, I see something completely different.  The process runs for 5 seconds until the stop call.  The two threads alternate sending key events, which are all received in the main thread.  Ditto for built 32-big debug 3.6 and 3.8.  

The only problem is that the first t.join() hangs because of a thread deadlock bug.  t.join() blocks until exits. does not exit until the last event_generate, with running=False, returns.  But that blocks until dummy_handler runs.  Dummy_handler does not run when the main thread is blocked by t.join.

I fixed this by not generating events when running is False.  The revised program exits properly.

    def run(self):
        tid = self.ident
        while True:
            c = random.choice(string.ascii_letters)
            print(running, "%d: sending '%s'"%(tid,c),file=sys.stderr)
            if running:

I suppose there is a teeny possibility that 'running' could be flipped between the test and the call.  Can that be prevented with a lock?

Another possibility is for stop() to change conditions so that '' fails with an exception, and change if/else to for/except.  My first try sort of works in IDLE but not the console.
Date User Action Args
2018-05-03 19:43:26terry.reedysetrecipients: + terry.reedy, gvanrossum, serhiy.storchaka, Ivan.Pozdeev
2018-05-03 19:43:26terry.reedysetmessageid: <>
2018-05-03 19:43:26terry.reedylinkissue33412 messages
2018-05-03 19:43:26terry.reedycreate