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

setupterm exit silently on Python 3.12 #50

Closed
irvinren opened this issue Nov 20, 2023 · 18 comments · Fixed by #53
Closed

setupterm exit silently on Python 3.12 #50

irvinren opened this issue Nov 20, 2023 · 18 comments · Fixed by #53
Labels
bug Something isn't working

Comments

@irvinren
Copy link

after pip install windows-curses==2.3.2 setupterm failed, python process exit silently.

from _curses import setupterm
setupterm(term="xterm",fd=1)

@irvinren
Copy link
Author

I am running on windows 10 with the Cpython 3.12 downloaded from python.org

@irvinren
Copy link
Author

can you speed up to deal with this issue? It impacts my software development.

@irvinren
Copy link
Author

irvinren commented Nov 26, 2023

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`

@jasonbu
Copy link

jasonbu commented Nov 29, 2023

same issue, work all right on my python3.11, exit silently on python3.12

@kartben
Copy link

kartben commented Nov 29, 2023

@gschizas would you have any insights?

@irvinren
Copy link
Author

irvinren commented Dec 1, 2023

@stephanosio isn't it a bug? Is this project still active?

@stephanosio
Copy link
Member

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

@irvinren
Copy link
Author

irvinren commented Dec 1, 2023

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

@edreamleo
Copy link

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.

@edreamleo
Copy link

The _curses module defines setupterm, so _curses.cp312-win_amd64.pyd seems the likely culprit.

Probably a bad build somehow.

@gotyaoi
Copy link
Contributor

gotyaoi commented Apr 27, 2024

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.

@gotyaoi
Copy link
Contributor

gotyaoi commented Apr 27, 2024

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.

@gotyaoi
Copy link
Contributor

gotyaoi commented May 4, 2024

@stephanosio I could put in a PR, if that's desired?

@stephanosio
Copy link
Member

@stephanosio I could put in a PR, if that's desired?

That would be greatly appreciated.

@stephanosio
Copy link
Member

Leaving this issue open until it is confirmed to be fixed by others.

@stephanosio stephanosio reopened this May 5, 2024
@stephanosio
Copy link
Member

v2.3.3a1 has been released with the proposed fix from #53. Please test it out and let me know if it fixes the issue.

@stephanosio stephanosio added the bug Something isn't working label May 5, 2024
@LewisNeal
Copy link

v2.3.3a1 worked for me running python 3.12.2

@stephanosio
Copy link
Member

v2.3.3, which fixes this issue, has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
7 participants