ulfalizer / Kconfiglib

A flexible Python 2/3 Kconfig implementation and library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Menuconfig fails in MacOs with Python 3 when the terminal is resized

dobairoland opened this issue · comments

Menuconfig works fine in MacOs with Python 2. However, it fails with Python 3 with the following error when the terminal window is resized:

File "/Users/xy/esp/esp-idf/tools/kconfig_new/menuconfig.py", line 3300, in <module>
_main()
File "/Users/xy/esp/esp-idf/tools/kconfig_new/menuconfig.py", line 672, in _main
menuconfig(standard_kconfig(_doc_))
File "/Users/xy/esp/esp-idf/tools/kconfig_new/menuconfig.py", line 741, in menuconfig
print(curses.wrapper(_menuconfig))
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/curses/_init_.py", line 102, in wrapper
return func(stdscr, *args, **kwds)
File "/Users/xy/esp/esp-idf/tools/kconfig_new/menuconfig.py", line 844, in _menuconfig
c = _getch_compat(_menu_win)}}
File "/Users/xy/esp/esp-idf/tools/kconfig_new/menuconfig.py", line 3171, in _getch_compat
c = win.get_wch()
_curses.error: no input

This issue was observed in https://github.com/espressif/esp-idf but probably it can be reproduced without it. We reproduced it on several machines.

The issue cannot be observed in Linux nor Windows. It works there as it is expected.

Don't have a Mac handy, unfortunately.

To narrow it down, try running python3 menuconfig.py <dummy file> directly outside CMake on this dummy file:

config FOO
	bool "foo"

Also try running this program:

import curses


def main(stdscr):
    while True:
        stdscr.get_wch()


curses.wrapper(main)

I wonder if it might be related to this issue. I get the same crash on Linux if I add import rlcompleter to the small test program.

I've tried and both menuconfig.py and test program are failing.
Both pyenv installed python 3.8 and xcode's python 3.7 behave the same way:

Traceback (most recent call last):
  File "t.py", line 9, in <module>
    curses.wrapper(main)
  File "/Users/ku/.pyenv/versions/3.8.0/lib/python3.8/curses/__init__.py", line 105, in wrapper
    return func(stdscr, *args, **kwds)
  File "t.py", line 6, in main
    stdscr.get_wch()
_curses.error: no input
Using default symbol values (no '.config')
Traceback (most recent call last):
  File "menuconfig.py", line 3291, in <module>
    _main()
  File "menuconfig.py", line 663, in _main
    menuconfig(standard_kconfig(__doc__))
  File "menuconfig.py", line 732, in menuconfig
    print(curses.wrapper(_menuconfig))
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "menuconfig.py", line 835, in _menuconfig
    c = _getch_compat(_menu_win)
  File "menuconfig.py", line 3162, in _getch_compat
    c = win.get_wch()
_curses.error: no input

@kumekay
Thanks for testing it out.

Could you try running this C program as well, to try to rule out Python-specific issues?

#include <curses.h>
#include <stdio.h>
#include <wchar.h>

int main(void)
{
	initscr();
	while (1) {
		wint_t wch;

		if (get_wch(&wch) == ERR) {
			endwin();
			puts("error");
			break;
		}
		if (wch == KEY_RESIZE) {
			endwin();
			puts("ok");
			break;
		}
	}
}

Compile it with

$ gcc test-resize.c $(pkg-config --cflags --libs ncursesw) -o test-resize

Exits with "ok" on my Linux box when the terminal is resized.

Just remembered that MacOS switched over to clang, so might need to make it

$ clang test-resize.c $(pkg-config --cflags --libs ncursesw) -o test-resize

It works on my mac as well:

./test-resize
ok
echo $?      
0

(The only change I made in your code was addition of #include <wchar.h> otherwise it didn't want to compile)

(The only change I made in your code was addition of #include <wchar.h> otherwise it didn't want to compile)

Always forget something...

It works on my mac as well:

./test-resize
ok
echo $?      
0

Looks like the issue might be on the Python side in that case. I'll see if I can find a Mac to tinker a bit.

Not against adding a workaround if it turns out to be a common problem with Python 3 installations on macOS, but it'd be nice to understand what's going on first at least.

@dobairoland @kumekay
Got this from asking around on the Zephyr slack (another guy could reproduce the crash though):

I just tried that on my mac and it does not crash when I resize the window.

running Catalina 10.15.2, iTerm2 and python3 3.7.3 bundled.

What macOS version are you running? Know how you installed Python 3?

I suspect the issue is with some third-party Python 3 package.

Thank you @ulfalizer for looking into this. We tried with another colleague and he has Catalina 10.15.2 as well and Python 3.7.4 installed with homebrew. It did crash on his computer as well.

@kumekay tried on two of his computers and I think he installed Python with pyenv. @kumekay, please give more info about your system setup.

Could you try the bundled Python 3 too?

Could you try the bundled Python 3 too?

@david-cermak Could you please try it?

@ulfalizer have checked with the bundled python3 3.7.3 on Catalina 10.15.2 it crashed in both the default Terminal and the iTerm2

@david-cermak
Same thing for this test program?

import curses


def main(stdscr):
    while True:
        stdscr.get_wch()


curses.wrapper(main)

Wonder what's going on for the guy who didn't have issues.

Yes, the same with the test program

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    curses.wrapper(main)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "test.py", line 6, in main
    stdscr.get_wch()
_curses.error: no input

Could you try /usr/bin/python3 as well? I wonder if Xcode comes with a separate Python.

Might not be separate from looking at this SO answer.

Yes, the /usr/bin/python3 is what I tried

Yes, the /usr/bin/python3 is what I tried

Alright, thanks. I reported a bug at https://www.apple.com/feedback/macos.html, though it seems to be a catch-all for macOS issues, so maybe it'll go into a black hole.

There seems to be some Feedback Assistant thing too, though I'm not sure I can access it without a Mac.

Anyway, here's what I wrote, in case you feel you like reporting it elsewhere:

This code crashes with '_curses.error: no input' when the terminal is resized.
It works fine (as in, curses.KEY_RESIZE is returned) on Linux and FreeBSD.

    import curses


    def main(stdscr):
        while True:
            stdscr.get_wch()


    curses.wrapper(main)

Came up in https://github.com/ulfalizer/Kconfiglib/issues/84.

Should probably add a workaround in the meantime.

Pushed out a release with a fix: 68bcecd

Would be nice to figure out and report the root issue at some point though.

Thank you @ulfalizer for working on this and releasing the workaround.