GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Dead code in tkinter · Issue #140494 · python/cpython

Dead code in tkinter #140494

New issue
Copy link
New issue
Copy link
Open
Open
Dead code in tkinter#140494
Copy link
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-tkintertype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

Description

@mdehoon
mdehoon
opened on Oct 23, 2025
Issue body actions

Bug report

Bug description:

Modules/_tkinter.c always defines TCL_THREADS:

/* If Tcl is compiled for threads, we must also define TCL_THREAD. We define
   it always; if Tcl is not threaded, the thread functions in
   Tcl are empty.  */ 
#define TCL_THREADS

but in two places in Modules/_tkinter.c , we check if TCL_THREADS is defined:

#ifdef TCL_THREADS
static Tcl_ThreadDataKey state_key;
typedef PyThreadState *ThreadSpecificData;
#define tcl_tstate \
    (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*)))
#else
static PyThreadState *tcl_tstate = NULL;
#endif

and

#ifndef TCL_THREADS
    if (v->threaded) {
        PyErr_SetString(PyExc_RuntimeError,
                        "Tcl is threaded but _tkinter is not");
        Py_DECREF(v);
        return 0;
    }
#endif

Especially the latter is confusing, as this code block is not compiled and the test is never executed.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-140494: require that Tcl is built with thread support #141241
  • gh-140494: Remove dead code ifndef TCL_THREADS, which is always defined #152841

Activity

  1. mdehoon
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 23, 2025
  2. terryjreedy
    added
    topic-tkinter
    on Oct 23, 2025
  3. terryjreedy commented on Oct 23, 2025

    @terryjreedy
    terryjreedy
    on Oct 23, 2025
    Member
    More actions

    tcl/tk 8.5 was by default compiled without thread_support. 8.6 by default is, and perhaps the option is gone. Thread support was once optional in python, but now is mandatory so _tkinter should support them also.

    I suspect that the define and the comment before could be eliminated (if these are the only two uses) and the code between #ifdef TCL_THREADS and #ELSE# made unconditional and the other code eliminated. @serhiy-storchaka ?

  4. StanFromIreland
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    type-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 23, 2025
  5. serhiy-storchaka commented on Oct 23, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Oct 23, 2025
    Member
    More actions

    It was unconditionally enabled in b5bfb9f, 23 years ago. Well, I think we can remove this code now. Note that some comments may be need to be updated.

    Reacted by yihong, A.Ibrahim and mdehoon
  6. mdehoon commented on Oct 24, 2025

    @mdehoon
    mdehoon
    on Oct 24, 2025
    ContributorAuthor
    More actions

    We still need to #define TCL_THREADS , otherwise tkinter won't compile.

    Should we require that tcl/tk was compiled with thread support, or should we still allow tcl/tk without thread support?

  7. serhiy-storchaka
    added
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Jul 17, 2026
  8. serhiy-storchaka commented on Jul 17, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 17, 2026
    Member
    More actions

    I think we can drop support of non-threaded Tcl/Tk in main. AFAIK, 8.6 is threaded by default, and 9.0 is always threaded. But the minimal supported version was still 8.5.12. Some distributors can still need to build without threaded support, they may even patch #define TCL_THREADS. So this is main-only change.

    To make backporting easier, it is better to hold these changes until we fix other issues.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-tkintertype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.