Skip to content

gh-154801: expose Tcl notifier to external event loops - #155805

Draft
BHUVANSH855 wants to merge 1 commit into
python:mainfrom
BHUVANSH855:gh-154801-tcl-notifier
Draft

gh-154801: expose Tcl notifier to external event loops#155805
BHUVANSH855 wants to merge 1 commit into
python:mainfrom
BHUVANSH855:gh-154801-tcl-notifier

Conversation

@BHUVANSH855

@BHUVANSH855 BHUVANSH855 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

This is a draft implementation for gh-154801, which proposes exposing Tcl's external event-loop/notifier API through _tkinter.

The goal is to allow Tcl/Tk to participate in an event loop managed outside Tcl, for example a Python-level loop shared with another GUI toolkit, without requiring polling or additional threads.

This proposal has also been discussed on Discourse:

https://discuss.python.org/t/connecting-asyncio-and-tkinter-event-loops/14722/40

Current implementation

The current draft explores exposing:

  • Tcl_SetNotifier() through _tkinter.set_notifier()
  • Tcl_SetServiceMode() through _tkinter.set_service_mode()
  • Tcl_ServiceAll() through _tkinter.service_all()
  • Tcl_QueueEvent() through _tkinter.queue_event()
  • Tcl notifier callbacks bridged into Python
  • Initial tests for notifier registration, event queueing, timers, and external-loop file-handler integration

The basic event-queue path is working locally, and the implementation has been tested against Tcl 8.6.14.

Open design questions

This PR is intentionally a draft because the notifier/file-handler boundary still needs design feedback.

In particular, guidance would be appreciated on:

  • whether the proposed _tkinter API surface is appropriate;
  • whether create_file_handler should expose a Python callback object, as shown in the issue's reference implementation, rather than the current native callback representation;
  • the preferred ownership/lifetime model for file-handler callbacks;
  • any concerns with using Tcl_QueueEvent() and Tcl_ServiceAll() from _tkinter;
  • whether there are existing Tcl/Tk or CPython patterns that should be followed for the notifier callback bridge.

Status

This is not ready for merge. The purpose of this draft PR is to get early maintainer feedback on the API and architecture before the remaining notifier file-handler lifetime/dispatch details are finalized.

cc @serhiy-storchaka

Refs: gh-154801

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant