Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dobairoland opened this issue Jan 2, 2020 · 19 comments
Closed

Comments

@dobairoland
Copy link

dobairoland commented Jan 2, 2020

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.

@ulfalizer
Copy link
Owner

ulfalizer commented Jan 2, 2020

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.

@kumekay
Copy link

kumekay commented Jan 3, 2020

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

@ulfalizer
Copy link
Owner

ulfalizer commented Jan 3, 2020

@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.

@ulfalizer
Copy link
Owner

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

@kumekay
Copy link

kumekay commented Jan 4, 2020

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)

@ulfalizer
Copy link
Owner

(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.

@ulfalizer
Copy link
Owner

ulfalizer commented Jan 9, 2020

@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.

@dobairoland
Copy link
Author

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.

@ulfalizer
Copy link
Owner

Could you try the bundled Python 3 too?

@dobairoland
Copy link
Author

Could you try the bundled Python 3 too?

@david-cermak Could you please try it?

@david-cermak
Copy link

@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

@ulfalizer
Copy link
Owner

ulfalizer commented Jan 9, 2020

@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.

@david-cermak
Copy link

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

@ulfalizer
Copy link
Owner

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

@ulfalizer
Copy link
Owner

Might not be separate from looking at this SO answer.

@david-cermak
Copy link

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

@ulfalizer
Copy link
Owner

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.

ulfalizer added a commit that referenced this issue Jan 12, 2020
get_wch() has started raising curses.error when resizing the terminal on
some macOS Python installations. Work around for now by falling back on
getch(), which still works.

See #84. Needs more
investigation, but I don't have a Mac handy.

Based on #85, but with some
more comments.
@ulfalizer
Copy link
Owner

Pushed out a release with a fix: 68bcecd

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

ulfalizer added a commit to ulfalizer/zephyr that referenced this issue Jan 13, 2020
Update menuconfig (and kconfiglib and guiconfig, just to sync) to
upstream revision 424d0d38e7, to get this commit in, which works around
a crash on some macOS Python installations.

    menuconfig: Work around crash on resize on some macOS systems

    get_wch() has started raising curses.error when resizing the
    terminal on some macOS Python installations. Work around for now by
    falling back on getch(), which still works.

    See ulfalizer/Kconfiglib#84. Needs more
    investigation, but I don't have a Mac handy.

    Based on ulfalizer/Kconfiglib#85, but with
    some more comments.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
carlescufi pushed a commit to zephyrproject-rtos/zephyr that referenced this issue Jan 13, 2020
Update menuconfig (and kconfiglib and guiconfig, just to sync) to
upstream revision 424d0d38e7, to get this commit in, which works around
a crash on some macOS Python installations.

    menuconfig: Work around crash on resize on some macOS systems

    get_wch() has started raising curses.error when resizing the
    terminal on some macOS Python installations. Work around for now by
    falling back on getch(), which still works.

    See ulfalizer/Kconfiglib#84. Needs more
    investigation, but I don't have a Mac handy.

    Based on ulfalizer/Kconfiglib#85, but with
    some more comments.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
@dobairoland
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants