| Ticket UUID: | da5f2266df6573b4adc81631697ae99976ec4f89 | |||
| Title: | update idletasks services queued events | |||
| Type: | Bug | Version: | 8.6.11 | |
| Submitter: | erikleunissen | Created on: | 2021-04-26 10:28:21 | |
| Subsystem: | 69. Events | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Open | Last Modified: | 2021-04-26 16:19:43 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
Expected
========
The command "update idletasks" selectively services idle callbacks, skipping events associated with the event queue.
Observed
========
The test script in the attached file exercise.tcl exercises the inconsistent behaviour. It uses an event, queued by [thread::send], as an example.
The misbehaviour shows when an extraneous command [wm geometry ...] is inserted before calling "update idletasks".
Therefore, you may comment out this call to "wm geometry" (line a. in the test script) to observe the regular, expected behaviour. This also indicates some undesired interference between [wm geometry ...] and [update idletasks]".
This observation was done under Linux with Tcl/Tk 8.6.11
Cursory analysis
================
A cursory inspection of the C code for the event loop indicates that the misbehaviour happens for any event put onto the event queue directly [1], not just events queued by [thread::send] [2].
[1] The misbehaviour appears to show for those events that are not associated with an event source (which needs to be queried first before the event is queued).
[2] Note that this doesn't apply [thread::send] sending work to its own thread. Such work isn't put onto the event queue. Instead it is scheduled as an idle callback.
| |||
| User Comments: |
erikleunissen added on 2021-04-26 16:19:43:
Hi,
Let me respond to a few passages in your (the previous) post:
A. Regarding:
>
> Now you are asking that the same change be made in Tk,
> throwing Jan's caution to the winds.
>
Two points:
1. "the same change", you write. Where did you see me ask that for? Or even imply such a specific change? For all I care, all sensible options are open.
2. also, I don't see the relation with Tcl ticket [0221b993a1], other than that both issues are in the same ball park (of the event loop). I wonder whether you appreciated to its full extent what I wrote with:
"A cursory inspection of the C code for the event loop indiciates that the misbehaviour happens for any event put onto the event queue directly"
and the footnote that it refers to.
B. Regarding:
>
> You are probably assuming that the Tk update command, etc ...
>
No, it's worse. Please consider this passage from the manual page:
"Most display updates are performed as idle callbacks, so update idletasks will cause them to run. However, there are some kinds of updates that only happen in response to events, such as those triggered by window size changes; these updates will not occur in update idletasks."
By accident, I made the test script that I provided exercise what's written in the last sentence.
I'm sorry. That was very uncareful and insubordinate of me.
C. Regarding:
>
> The choice between update and update idletasks in Tk is not a choice between
> processing all events and running only idle tasks. It is much more than that.
>
Sure, sorry again for touching on this sensitive subject.
D. Regarding:
>
> What do you propose to do about the calls to XSync? ...
>
I wouldn't dare to propose anything, not anymore now.
Please disregard the matter altogether.
Erik.
marc_culler (claiming to be Marc Culler) added on 2021-04-26 13:12:34: Starting in 1998 or earlier the Tcl update idletasks command would run Tcl_DoOneEvent(flags) with flags = TCL_WINDOW_EVENTS|TCL_IDLE_EVENTS|TCL_DONT_WAIT You filed Tcl ticket [0221b993a1] about this same topic, and that was resolved by removing the TCL_WINDOW_EVENTS flag (and leaving the TCL_DONT_WAIT flag, which is actually redundant when only processing idle tasks.) Jan made that change on the grounds that window events are really Tk events, and Tk has its own update command, so it would be safe to change the Tcl update command. But to be careful Jan opted only to make the change in 8.7. Now you are asking that the same change be made in Tk, throwing Jan's caution to the winds. But the Tk update command is a completely different animal from the Tcl update command. You are probably assuming that the Tk update command, like the Tcl update command, simply runs Tcl_DoOneEvent with flags = TCL_ALL_EVENTS|TCL_DONTWAIT. But that is not the case. The Tk update command runs a loop in which it alternates between processing all events and calling XSync until there are no events left on the event queue. As the comment in tkCmds.c says: /* * Handle all pending events, sync all displays, and repeat over and over * again until all pending events have been handled. ... The choice between update and update idletasks in Tk is not a choice between processing all events and running only idle tasks. It is much more than that. What do you propose to do about the calls to XSync? This has been a huge headache for the macOS port, and the Tk tests are full of calls to both update and update idletasks which are needed to avoid timing issues and which often have to be handled differently on different platforms. On macOS, which has no natural analogue for XSync, the current implementation of XSync processes all expired timer events. This is needed for some of the tests to pass. XSync on macOS does not process window events, but that does happen in the other part of the loop. While I think there are lots of issues with the Tk update command, I can guarantee that making any change to it would produce lots and lots of test failures, different on different platforms, and would likely break lots of Tk applications. Changing it requires being very careful and doing lots of testing. | |||
Attachments:
- exercise.tcl [download] added by erikleunissen on 2021-04-26 10:28:59. [details]
