setupterm exit silently on Python 3.12
after pip install windows-curses==2.3.2 setupterm failed, python process exit silently.
from _curses import setupterm setupterm(term="xterm",fd=1)
I am running on windows 10 with the Cpython 3.12 downloaded from python.org
can you speed up to deal with this issue? It impacts my software development.
in the curses module of cpython 3.12,
the function initscr() will call setupterm which quit silently on my machine.
cat d:\Python312\Lib\curses\init.py
`def initscr(): import _curses, curses # we call setupterm() here because it raises an error # instead of calling exit() in error cases. setupterm(term=_os.environ.get("TERM", "unknown"), fd=_sys.stdout.fileno()) stdscr = _curses.initscr() for key, value in curses.dict.items(): if key[0:4] == 'ACS' or key in ('LINES', 'COLS'): setattr(curses, key, value)
return stdscr`
same issue, work all right on my python3.11, exit silently on python3.12
@gschizas would you have any insights?
@stephanosio isn't it a bug? Is this project still active?
@stephanosio isn't it a bug? Is this project still active?
@irvinren Hi. The original author of this project is no longer active and this project is more or less on life support. I currently lack the bandwidth to look into this issue at the moment -- any help from a third party would be greatly appreciated.
@stephanosio isn't it a bug? Is this project still active?
@irvinren Hi. The original author of this project is no longer active and this project is more or less on life support. I currently lack the bandwidth to look into this issue at the moment -- any help from a third party would be greatly appreciated.
Is there anything I can do to help you? To be frank, I could support it to some degree if it doesn't cause too much effort.
Hello all. I am the author of Leo. Leo's cursesGui2 plugin suffers the same problem.
There is an easy workaround. The cursesGui2 plugin contains only one call to curses.initscr(). I replaced it as follows:
if 1: # Call our own version of curses.initscr().
import _curses
# This crashes on Python 3.12.
# setupterm(term=_os.environ.get("TERM", "unknown"),
# fd=_sys.__stdout__.fileno())
stdscr = _curses.initscr()
for key, value in _curses.__dict__.items():
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
setattr(curses, key, value)
# return stdscr
else:
stdscr = curses.initscr()
If your program calls curses.initscr from multiple places, wrap the code above in a function.
I tested this hack on Python 3.9, 3.11, 3.12.
HTH.
The _curses module defines setupterm, so _curses.cp312-win_amd64.pyd seems the likely culprit.
Probably a bad build somehow.
I don't know if this is for sure the culprit, but it's possible that the generated argument clinic code should be regenerated, since the error is a memory access violation in PyArg_UnpackKeywords. A test run of clinic.py produces a very different _cursesmodule.c.h than the one committed currently.
Seems like I was right. With a small patch, I was able to build a new working 3.12 wheel after running clinic.py to regenerate the clinic headers.
diff --git a/py312/_cursesmodule.c b/py312/_cursesmodule.c
index 4437114..102bb41 100644
--- a/py312/_cursesmodule.c
+++ b/py312/_cursesmodule.c
@@ -1119,9 +1119,9 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
_curses.window.box
[
- verch: object(c_default="_PyLong_GetZero()") = 0
+ verch: object(c_default="PyLong_FromLong(0)") = 0
Left and right side.
- horch: object(c_default="_PyLong_GetZero()") = 0
+ horch: object(c_default="PyLong_FromLong(0)") = 0
Top and bottom side.
]
/
The current clinic header for _cursesmodule.c was manually modified to include that change, so this just slips it into the source instead.
@stephanosio I could put in a PR, if that's desired?
@stephanosio I could put in a PR, if that's desired?
That would be greatly appreciated.
Leaving this issue open until it is confirmed to be fixed by others.
v2.3.3a1 has been released with the proposed fix from https://github.com/zephyrproject-rtos/windows-curses/pull/53. Please test it out and let me know if it fixes the issue.
v2.3.3a1 worked for me running python 3.12.2
v2.3.3, which fixes this issue, has been released.