cpython icon indicating copy to clipboard operation
cpython copied to clipboard

REPL does not work in msys2, ConEmu terminals on windows

Open f881f066-8e25-4283-8c24-394cb2f93588 opened this issue 7 years ago • 5 comments

BPO 34091
Nosy @pfmoore, @ericvsmith, @tjguk, @vadmium, @zware, @zooba, @segevfiner, @maxnoe

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-07-11.09:02:12.048>
labels = ['3.8', 'type-bug', '3.7', 'OS-windows']
title = 'REPL does not work in msys2, ConEmu terminals on windows'
updated_at = <Date 2018-07-13.09:22:15.859>
user = 'https://github.com/maxnoe'

bugs.python.org fields:

activity = <Date 2018-07-13.09:22:15.859>
actor = 'Segev Finer'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Windows']
creation = <Date 2018-07-11.09:02:12.048>
creator = 'maxnoe'
dependencies = []
files = []
hgrepos = []
issue_num = 34091
keywords = []
message_count = 4.0
messages = ['321417', '321422', '321437', '321585']
nosy_count = 8.0
nosy_names = ['paul.moore', 'eric.smith', 'tim.golden', 'martin.panter', 'zach.ware', 'steve.dower', 'Segev Finer', 'maxnoe']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue34091'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8']

The REPL won't start in interactive mode, it only starts when explicitly given the -i option.

The problems IPython is having, e.g. missing syntax highlighting and no tab completion should have the same root.

See this issue for mingw: https://github.com/Alexpux/MINGW-packages/issues/730

They fixed it by patching python using this patch: https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-python3/1700-cygpty-isatty.patch

And this issue at msys2: https://sourceforge.net/p/msys2/tickets/32/

The problem as I understand it is that Msys uses a pipe, but Python by default limits interactive REPL mode to terminals only. The same thing happens if you start Python on a pipe some other way, for instance “cat | python” vs “cat | python -i”.

I would prefer if Python decided to use interactive mode when no file name is given, rather than by checking if the file is a terminal. But that would break compatibility.

Another tip with Msys: enable unbuffered output with “python -u”. Otherwise output gets buffered, won’t be seen immediately, and may be lost if there is an unclean exit.

vadmium avatar Jul 11 '18 09:07 vadmium

Tab completion does not work in the REPL even when started with -i -u, so there might be a deeper problem than just the PIPE that's preventing python from starting in interactive mode.

I'd assume this is using ConEmu's ChildGui which means it hacks up a MinTTY window to appear inside ConEmu's GUI. MinTTY doesn't use a real terminal but rather pipes as the processes stdio. Any native (non-MSYS2) Windows program would have a problem with this.

The known workaround is to launch such programs using WinPTY (Available in the MSYS2 pacman), which creates a real console for the program in the background and communicates it's input/output so that it appear in the original console.

Sadly that is a limitation of Windows, as Windows does not supply a proper PTY interface and MSYS2/MinTTY choose not to use something like WinPTY by default.

I think it has been fixed since 2022-09-24, because ConPTY support is enabled on msys2.

Please see:

  • https://www.msys2.org/news/
  • https://github.com/msys2/MSYS2-packages/commit/3dad03537cbf09e11ac85e6e33e4ece56f757339

GalaxySnail avatar Dec 09 '22 16:12 GalaxySnail