Skip to content

bpo-41176: revise Tkinter mainloop dispatching flag behavior #21299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

richardsheridan
Copy link

@richardsheridan richardsheridan commented Jul 3, 2020

new method `dispatching` on tkinter, Misc, and _tkinter.tkapp
DeprecationWarning issued on implicit wait
Docstring changes
Comment stubs for eventual removal of WaitForMainloop
Add setmainloopwaitattempts method to _tkinter.tkapp
Replace all usages of update_idletasks in tests with update.

update_idletasks does not in fact process all pending events.
It updates the idle tasks only, without touching the normal event queue. This is not normaly a problem... until it is.

Update docstrings to clarify.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@richardsheridan

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Contributor

@E-Paine E-Paine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally looking very good, though there are a few things I feel need addressing:

  1. Please sign your CLA! - Unfortunately, we cannot legally accept the patch until the CLA has been signed. Once it has been approved, an asterisk will appear next to your name on bugs.python and the bots should change the PR labels automatically.
  2. New methods = new docs - As we are adding new methods, these should be fully documented in the docs (probably in Doc/library/tkinter.rst)
  3. Whatsnew? - I feel this is definitely a big enough change to be worth adding to the 3.10 whatsnew
  4. ACKS - Because this is your first non-trivial patch, please feel free to add yourself to Misc/ACKS

This is just an initial look at the code and I have not tested the patch yet, though I hope to do this soon.

Thank you for this PR: as I have already said it looks very good and the code has now persuaded me in favour of deprecating WaitForMainloop. I may, at some point, drag Terry into this for his opinion on the changes (and how they could affect IDLE)

@richardsheridan
Copy link
Author

Thanks @E-Paine!

Re: CLA, I have 2 separate signed agreements in my inbox now, I hope I'm not doing something wrong! T_T

I'll see what I can do about these other points this weekend, otherwise it may have to wait another week.

@E-Paine
Copy link
Contributor

E-Paine commented Jul 5, 2020

I forgot to mention this previously, but you will also need to add a news entry. The easiest way is probably to click "details" on bedevere/news, "sign-in" and then install blurb_it to your CPython fork.

richardsheridan and others added 15 commits July 5, 2020 08:10
Exceptions raised in the thread will be ignored, so capture the conditions of interest and assert them after joining.

Add WaitForMainloop warning on timeout too.
Still need to raise if not dispatching
Too hard to tell which flag broke if using the loop
In preparation for supporting multiple dispatchers with an IntEnum
failing with timeout gives no helpful debugging info, so try to eliminate all possible hangs
Seems to cause CI to never exit mainloop at least on Ubuntu. No idea why yet.
@richardsheridan
Copy link
Author

richardsheridan commented Jul 6, 2020

@E-Paine sorry, I need help with CI since I can't reproduce this myself. Ubuntu suddenly began hanging in mainloop but it persists even after I reverted the changes. See this diff between 648434f and b58f8a1.

@E-Paine
Copy link
Contributor

E-Paine commented Jul 12, 2020

Great! I just ask (hopefully) one last change before I approve the changes (and we call in a core-dev): please indent the Tk class methods (in the docs) so it looks clearer and Sphinx registers them as methods of that class (you can then also remove Tk. at the start of the methods)

@richardsheridan
Copy link
Author

I stumbled into https://bugs.python.org/issue39093 in another project. I tried to make a comment on the bug tracker but submitting the comment there only produces errors.

I want to +1 the uncommenting solution. The problem occurs on del rather than specifically in the gc somewhere (it happens when refs drop to zero too), so I wouldn't worry too much about killing the garbage collector.

It also looks like fixing the python part would be about 3 lines of non-user-facing code with weakrefs. Are you sure that's no-go?

Would it be any help to roll https://bugs.python.org/issue39093 into this PR or is keeping them separate best?

richardsheridan added a commit to richardsheridan/matplotlib that referenced this pull request Sep 24, 2020
current status: Prone to races and hard-to-diagnose timeouts

(see python/cpython#21299)
def mainloop(n=0):
"""Run the main loop of Tcl."""
_default_root.tk.mainloop(n)
def mainloop(threshold=0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API change that should be flagged?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this was just meant to make the variable name a bit more descriptive, but it could break (rare) user code that relied on setting n as a keyword argument.

richardsheridan added a commit to richardsheridan/matplotlib that referenced this pull request Oct 24, 2020
current status: Prone to races and hard-to-diagnose timeouts

(see python/cpython#21299)
@richardsheridan richardsheridan deleted the tkinter_dispatching branch May 3, 2021 22:50
@richardsheridan richardsheridan restored the tkinter_dispatching branch May 3, 2021 22:50
@tacaswell
Copy link
Contributor

Could this be re-opened and reconsidered?

@richardsheridan
Copy link
Author

If you can get the attention of a core dev for me, I can help with any last touches. But I can't invest the time to do a rewrite if that's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants