Delay a computation in another thread

eryk sun eryksun at gmail.com
Sat Sep 2 14:16:57 EDT 2017


On Sat, Sep 2, 2017 at 5:53 AM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
>
> The problem is that after the message is printed, the REPL's prompt is
> disrupted. This is especially annoying when I'm in the middle of typing a line.
> This is just a cosmetic flaw, but it would be nice if I could tell Python to
> redraw the current line.

This would be difficult on Windows. When the REPL reads from the
console, the main thread blocks on a system call, which varies
depending on the versions of Python and Windows. This is a remote
procedure call to the console host process (e.g. conhost.exe in
Windows 7+), which handles the cooked read while Python waits for the
result.

To get the level of control you're asking for, we'd have to implement
readline for the Windows console using low-level console functions
such as ReadConsoleInput. pyreadline currently implements this via
ctypes, but CPython would need a C extension.



More information about the Python-list mailing list