10000 bpo-41176: revise Tkinter mainloop dispatching flag behavior by richardsheridan · Pull Request #21299 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
90a6343
bpo-41176: Expose tkinter dispatching state
richardsheridan Jul 3, 2020
f426278
bpo-41176: Deprecate implicit mainloop waiting behavior
richardsheridan Jul 3, 2020
3350dbc
bpo-41176: additional docstring corrections
richardsheridan Jul 3, 2020
9db47cf
bpo-41176: Correct tkinter test usage of `update`
richardsheridan Jul 3, 2020
2817b2a
bpo-41176: Rename according to comment and use Clinic
richardsheridan Jul 4, 2020
8e4371f
bpo-41176: Address PR comments, add willdispatch test
richardsheridan Jul 5, 2020
3732864
bpo-41176: deduplicate warning code
richardsheridan Jul 5, 2020
6df6433
bpo-41176: rectify typo
richardsheridan Jul 5, 2020
0f609d7
bpo-41176: ACKS
richardsheridan Jul 5, 2020
ad89a27
bpo-41176: fix future behavior
richardsheridan Jul 5, 2020
49ab712
bpo-41176: inline thread flag checks
richardsheridan Jul 5, 2020
ba079da
bpo-41176: internal flag should flip, not just be true
richardsheridan Jul 5, 2020
7c5d9fb
bpo-41176: improve dispatching docstring
richardsheridan Jul 5, 2020
2f22316
bpo-41176: Update whatsnew
richardsheridan Jul 5, 2020
5e9965c
bpo-41176: whitespace
richardsheridan Jul 5, 2020
5872f5b
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 5, 2020
d130740
bpo-41176: data to method
richardsheridan Jul 5, 2020
648434f
bpo-41176: fix future behavior
richardsheridan Jul 6, 2020
44fe5fa
bpo-41176: Make dispatching return an int
richardsheridan Jul 6, 2020
fbddd0f
bpo-41176: attempt to expose CI error
richardsheridan Jul 6, 2020
b58f8a1
bpo-41176: revert internal memory of previous dispatching
richardsheridan Jul 6, 2020
ad7d6ec
bpo-41176: Attempt Ubuntu CI fix
richardsheridan Jul 7, 2020
a5bb180
bpo-41176: Attempt Ubuntu CI fix
richardsheridan Jul 7, 2020
2d557c5
bpo-41176: Quit, mainloop, dispatch docstrings
richardsheridan Jul 8, 2020
ff39387
bpo-41176: WIP Docs in tkinter.rst
richardsheridan Jul 9, 2020
8ea6c5f
bpo-41176: satisfy Doc make check
richardsheridan Jul 9, 2020
e7a0611
bpo-41176: use local max attempts variable
richardsheridan Jul 11, 2020
3165806
bpo-41176: dispatching returns PyBool
richardsheridan Jul 11, 2020
3912603
bpo-41176: update docstrings
richardsheridan Jul 11, 2020
4d81d59
bpo-41176: remove old deprecation warning
richardsheridan Jul 11, 2020
1f16b80
bpo-41176: update test with new deprecation and new future behavior
richardsheridan Jul 11, 2020
4ec839a
bpo-41176: update Docs
richardsheridan Jul 11, 2020
a5e4a86
bpo-41176: Comment new post-deprecation plan
richardsheridan Jul 11, 2020
8efe3fe
bpo-41176: New behavior plan: Doc and Warn fixes
richardsheridan Jul 11, 2020
bf2776c
bpo-41176: Resolve review issues
richardsheridan Jul 12, 2020
1be91e0
bpo-41176: Title underlines should be same length as title
richardsheridan Jul 12, 2020
ad6e882
bpo-41176: reset dispatching flag in test
richardsheridan Jul 12, 2020
6143a18
bpo-41176: layout Tk methods
richardsheridan Jul 12, 2020
516a385
bpo-41176: clarify dispatching() limitations
richardsheridan Jul 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-41176: Resolve review issues
  • Loading branch information
richardsheridan committed Jul 12, 2020
commit bf2776cae5cf7aae3c6aff2bb867640b0d7e8e7f
59 changes: 6 additions & 53 deletions Doc/library/tkinter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ so, usually, to use Tkinter all you need is a simple import statement::

.. FIXME: The following keyword arguments are currently recognized:

Below are a few of the methods provided by the :class:`Tk` class.

.. sectionauthor:: Richard Sheridan

.. method:: Tk.mainloop(threshold)

Enters the main loop of Tkinter. This repeatedly dispatches Tcl events until either
Expand All @@ -112,6 +116,8 @@ so, usually, to use Tkinter all you need is a simple import statement::
the main loop to be dispatching events. Some examples are: calling the :meth:`Tk.update` command,
:meth:`_tkinter.tkapp.doonevent`, and the python command line EventHook.

.. versionadded:: 3.10

.. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=0)

The :func:`Tcl` function is a factory function which creates an object much like
Expand All @@ -122,59 +128,6 @@ so, usually, to use Tkinter all you need is a simple import statement::
created by the :func:`Tcl` object can have a Toplevel window created (and the Tk
subsystem initialized) by calling its :meth:`loadtk` method.

.. TODO: Not a class, a module. how do I inline another module into this RST file?

.. class:: _tkinter

This module contains the low-level interface to Tk, and should rarely be
used directly by application programmers. It is usually a shared library
(or DLL), but might in some cases be statically linked with the Python
interpreter.

.. method:: _tkinter.create(screenName=None, baseName="", className="Tk", interactive=False, wantobjects=False, wantTk=True, sync=False, use=None)

This method is not for general use, but it is responsible for creating the
:class:`_tkinter.tkapp` object that can be found as the attribute
:attr:`Tk.tk`.

.. class:: _tkinter.tkapp

This object contains most of the low-level interface to Tk, and should
rarely be used directly by application programmers.

.. method:: _tkinter.tkapp.call(*args)

This method is the core entry point to Tcl/Tk. All Tkinter methods that
correspond to Tcl commands flow through here. This function is thread-safe,
meaning it can be used to issue commands to the Tcl interpreter in the main
thread from any other thread. If called from a thread, it will wait up to
one second for :meth:`Tk.mainloop` to be called, and then throw an error.
This error after one second is deprecated behavior, in the future it will
wait indefinitely for :meth:`Tk.mainloop`, :meth:`Tk.update`, or
:meth:`_tkinter.tkapp.dooneevent` to dispatch the event.

.. method:: _tkinter.tkapp.willdispatch()

This method circumvents the thread waiting behavior of :meth:`_tkinter.tkapp.call`
until after the next call to :meth:`Tk.mainloop` returns. Instead of throwing
an error after one second, :meth:`_tkinter.tkapp.call` will wait indefinitely
for :meth:`Tk.mainloop` to come up, or for some other entity to dispatch the
call. This method is essentially a promise to the thread that you "will dispatch" soon.
This method is deprecated and future behavior will be equivialent to calling this
function on load and after each invocation of :meth:`Tk.mainloop`.

.. method:: _tkinter.tkapp.setmainloopwaitattempts(num=10)

This method sets the number of 100 ms wait attempts of :meth:`_tkinter.tkapp.call`.
You can trigger an error immediately by setting num to 0. This method is deprecated
and future behavior will be equivalent to setting an infinite number of attempts.

.. method:: _tkinter.tkapp.dooneevent(flags=0)

Dispatches exactly one event from the Tcl event queue. Must be called from the same
thread as the Tcl interpreter. See Tcl documentation for Tcl_DoOneEvent() for information
on using the flags argument.

Other modules that provide Tk support include:

:mod:`tkinter.colorchooser`
Expand Down
10 changes: 5 additions & 5 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ Added the *root_dir* and *dir_fd* parameters in :func:`~glob.glob` and
(Contributed by Serhiy Storchaka in :issue:`38144`.)

sys
---
----

Add :data:`sys.orig_argv` attribute: the list of the original command line
arguments passed to the Python executable.
(Contributed by Victor Stinner in :issue:`23427`.)

tkinter
---
----

Added :meth:`tkinter.dispatching`, :meth:`tkinter.Misc.dispatching`, and
XXX Added :meth:`tkinter.dispatching`, :meth:`tkinter.Misc.dispatching`, and
:meth:`_tkinter.tkapp.dispatching`.
You can reliably call these to determine if the tkinter mainloop is running.

Expand All @@ -130,7 +130,7 @@ correctness of the new dispatching methods.
Added another new method :meth:`_tkinter.tkapp.setmainloopwaitattempts` which
can be used to obtain future thread waiting behavior.

(see also Deprications section)
(see also Deprecated section)
(Contributed by Richard Sheridan in :issue:`41176`.)


Expand All @@ -146,7 +146,7 @@ Optimizations
Deprecated
==========

The :mod:`tkinter` module has deprected the undocumented behavior where a
XXX The :mod:`tkinter` module has deprected the undocumented behavior where a
thread will implicitly wait up to one second for the main thread to enter
the main loop and then fail.
The undocumented :meth:`_tkinter.tkapp.willdispatch` method which sidesteps
Expand Down
26 changes: 11 additions & 15 deletions Lib/tkinter/test/test_tkinter/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import tkinter
import threading, time
import threading
import time
from test import support
from tkinter.test.support import AbstractTkTest
Expand Down Expand Up @@ -244,19 +244,15 @@ def target():
# keep the main thread from calling root.mainloop()
ready_for_mainloop.set()

# Everything after the event set must go in this try
# to guarantee that root.quit() is called in finally
try:
# self.assertTrue(root.dispatching()) but patient
for i in range (1000):
if root.dispatching():
thread_dispatching_eventually = True
break
time.sleep(0.01)
else: # if not break
thread_dispatching_eventually = False
finally:
root.after(0, root.quit)
# self.assertTrue(root.dispatching()) but patient
for i in range(1000):
if root.dispatching():
thread_dispatching_eventually = True
break
time.sleep(0.01)
else: # if not break
thread_dispatching_eventually = False
root.after(0, root.quit)

root = self.root

Expand All @@ -265,7 +261,7 @@ def target():

try:
ready_for_mainloop = threading.Event()
thread = threading.Thread(target=target, daemon=True)
thread = threading.Thread(target=target)
self.assertFalse(root.dispatching())
thread.start()
ready_for_mainloop.wait()
Expand Down
2 changes: 1 addition & 1 deletion Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static int mainloopwaitattempts = 10; // 1 second
static int
WaitForMainloop(TkappObject* self)
{
int i = 0;
int i;
int max_attempts = mainloopwaitattempts;
if (self->dispatching)
{
Expand Down
0