<i>channel reads prematurely from stdin on Windows</i> status still Open with 4 other changes
by
.
D 2025-11-14T10:42:47.852
J icomment Yes,\stkinter\shas\sbeen\saround\sfor\sa\slong\stime,\sbut\sthe\sevent\sloop\sinterface\sbetween\sPython\sand\sTcl/Tk\swas\salways\sclunky.\r\n\r\nIn\solder\sversions\sof\sPython,\stkinter\swould\suse\sTcl_CreateFileHandler\son\sUnix/Mac\sto\smonitor\sstdin\swhile\scalling\sTcl_DoOneEvent(0).\r\n\r\nOn\sWindows,\sTcl_CreateFileHandler\swould\snot\swork\sfor\sstdin,\sso\sinstead\stkinter\suses\sa\sbusy-wait\sloop.\sRecent\sversions\sof\sPython\suse\sa\sbusy-wait\sloop\son\sall\splatforms,\swhich\sis\sinefficient\sand\swasteful.\r\n\r\nIf\swe\scould\suse\sTcl_CreateChannelHandler\s(which\sis\savailable\son\sWindows),\sthen\swe\scould\scall\sTcl_DoOneEvent(0)\son\sall\splatforms,\sand\sget\srid\sof\sthe\sbusy-wait\sloop.\r\n\r\nThe\sproblem\sis\sthough\sthat\safter\sexiting\sthe\sTcl_DoOneEvent\sloop,\sPython\stries\sto\sread\sthe\snext\sline\sfrom\sstdin,\swhich\sdoesn't\swork\swith\sTcl_CreateChannelHandler\son\sWindows\sif\sthe\schannel\sreads\sdata\sfrom\sstdin\sin\sadvance.\r\n\r\nIt\smay\sbe\sthat\sthis\sproblem\sis\sjust\snot\ssolvable\sin\sthis\sway\sbecause\sof\sthe\sinherent\slimitations\son\sWindows.\sPerhaps\sa\sbetter\ssolution\sis\sfor\sPython\sto\simplement\sits\sown\sevent\sloop,\sand\suse\sit\sas\san\sexternal\sevent\sloop\sin\stkinter.\sThen\sPython\sretains\scontrol\sover\sthe\sevent\sloop\sand\smonitoring\sstdin.
J login anonymous
J mimetype text/x-markdown
J username mdehoon
K 1d0618000674abdf701021d69eaa858cbccf14a4
U anonymous
Z 8874c48fae51ff83cb18a90149932f7c