Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b5c7baa623aa524df0fdeb08dabc0fe6bb0da2d2798823c76651cea0b112b4bb
Ticket: 1d0618000674abdf701021d69eaa858cbccf14a4
channel reads prematurely from stdin on Windows
User & Date: anonymous on 2025-11-14 10:42:47
Changes

  1. icomment:
    Yes, tkinter has been around for a long time, but the event loop interface between Python and Tcl/Tk was always clunky.
    
    In older versions of Python, tkinter would use Tcl_CreateFileHandler on Unix/Mac to monitor stdin while calling Tcl_DoOneEvent(0).
    
    On Windows, Tcl_CreateFileHandler would not work for stdin, so instead tkinter uses a busy-wait loop. Recent versions of Python use a busy-wait loop on all platforms, which is inefficient and wasteful.
    
    If we could use Tcl_CreateChannelHandler (which is available on Windows), then we could call Tcl_DoOneEvent(0) on all platforms, and get rid of the busy-wait loop.
    
    The problem is though that after exiting the Tcl_DoOneEvent loop, Python tries to read the next line from stdin, which doesn't work with Tcl_CreateChannelHandler on Windows if the channel reads data from stdin in advance.
    
    It may be that this problem is just not solvable in this way because of the inherent limitations on Windows. Perhaps a better solution is for Python to implement its own event loop, and use it as an external event loop in tkinter. Then Python retains control over the event loop and monitoring stdin.
    
  2. login: "anonymous"
  3. mimetype: "text/x-markdown"
  4. username: "mdehoon"