Python3 curses segfault on stdscr.refresh()

62 Views Asked by At

Here is a very small program that demonstrates the problem:

#!/usr/bin/env python3

import curses
import sys
import time

def main():
    try:
        stdscr = curses.initscr()
        stdscr.clear()
        stdscr.addstr(0,0, "This is the prompt")
        stdscr.refresh()
        time.sleep(3)
    finally:
        curses.endwin()
    return 0


if __name__ == '__main__':
    sys.exit(main())

If I change python3 to python, it works perfectly. With python3, I get a segmentation fault in the call to stdscr.refresh().

2

There are 2 best solutions below

0
Edward Falk On

Answer: seems to be a bug in Apple's bundled Python. I went straight to python.org and downloaded their latest version and the problem seems to have gone away. Thanks for your help everybody.

Leaving this as not officially solved for a while, in case someone comes up with a better answer.

1
Chathura Abeywickrama On

Try using curses.wrapper instead of manually initializing and ending curses to see if it resolves the segmentation fault.

#!/usr/bin/env python3

import curses
import sys
import time

def main(stdscr):
    stdscr.clear()
    stdscr.addstr(0, 0, "This is the prompt")
    stdscr.refresh()
    time.sleep(3)

if __name__ == '__main__':
    curses.wrapper(main)