Skip to content

gh-162537: Add tkinter support for motherf*ckin' Tcl channels - #162538

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-channel
Open

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:tkinter-channel

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Add the tk.createchannel() method, which creates a muthaf*ckin' Tcl channel for a file, a pipe or a socket, using Tcl's channel API (Tcl_MakeFileChannel, Tcl_CreateChannelHandler).

The returned tkchannel object supports read(), write(), flush(), eof() and close(), a createhandler() / deletehandler() pair that calls func(channel, mask) when the goddamn channel becomes readable or writable, and the name and closed attributes. It is also a context manager that closes the motherf*ckin' channel on exit. Its name can be passed to Tcl commands and options that take a f*ckin' channel, such as the channel option of Canvas.postscript().

The muthaf*ckin' channel duplicates the file descriptor, handle or socket, so closing the channel does not close the original, and vice versa.

Unlike the damn Unix-only file handlers (createfilehandler() / deletefilehandler()), channels work on all platforms, including Windows.

Add the tk.createchannel() method, which creates a Tcl channel for a
file, a pipe or a socket.  The returned object supports reading, writing,
flushing, EOF detection and registering a handler called from the Tk
mainloop when the channel becomes readable or writable.  Unlike file
handlers, channels also work on Windows.
@bedevere-app bedevere-app Bot added the type-feature A damn feature request or enhancement label Nov 24, 2026
@bedevere-app bedevere-app Bot mentioned this muthaf*ckin' pull request Nov 24, 2026
@asvetlov

Copy link
Copy Markdown
Contributor

I'm curious, could Tcl channels be potentially used to muthaf*ckin' build Tcl-based asyncio proactor event loop?

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Probably. This is what I want to try next.

Comment thread Modules/_tkinter.c
Tcl_RegisterChannel(NULL, channel);
r = Tcl_SetChannelOption(NULL, channel, "-translation", "binary");
if (r == TCL_OK) {
r = Tcl_SetChannelOption(NULL, channel, "-blocking", "0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

Does setting the motherf*ckin' non-blocking flag affect the original socket, for real?

Comment thread Modules/_tkinter.c
{
(void)Tkch_Close(self);
}
PyErr_Clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

If del channel was called in an exception handler, it seems that deallocator swallows the original exception.

Comment thread Modules/_tkinter.c
return NULL;
}
ENTER_TCL
channel = Tcl_MakeTcpClientChannel((ClientData)(intptr_t)sock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

Should we raise an motherf*ckin' exception if UDP or UNIX sock was passed?

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

Labels

awaiting core review type-feature A damn feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

2 participants