3 ms·
Hmm, I'm not so sure that Tkinter example really solves the problem of performing background work without blocking the UI. Sure, the UI thread doesn't block, bu
by ptx 5y ago
Hmm, I'm not so sure that Tkinter example really solves the problem of performing background work without blocking the UI. Sure, the UI thread doesn't block, but instead the UI state (as the user continues interacting with it) can drift out of sync with the model when the controller thread is busy with other work.
The real issue in that example seems to be that the event loop needs to wait for both UI events and read/write readyness on the serial port. This could probably be handled either with createfilehandler[1] (although it doesn't work on Windows) or by dedicating a thread to handling the serial port and posting messages to the Tkinter event loop as suggested at the end.
[1] https://docs.python.org/3/library/tkinter.html#file-handlers https://docs.python.org/3/library/tkinter.html#file-handlers
- z3ugma 5y agoI think your last suggestion is dead on - think about the browser event loop where Messages can be triggered all the time from clicks, hovers etc. If you have 4 threads and all those threads are pushing Messages then the update thread only has to push the state change notifications and doesn't have to do much blocking of its own