Repository navigation
Description
Feature or enhancement
Isolate the _curses extension module. This means turning most global variables into module state variables.
Globals in the _curses extension module:
| Name | C type | Notes |
|---|---|---|
| PyCursesVersion | const char[] | Hard-coded C string; can remain a global |
| PyCursesError | PyObject * | |
| initialised_setupterm | int | Tells whether setupterm() has been called to initialise terminfo |
| initialised | int | Tells whether initscr() has been called to initialise curses |
| initialisedcolors | int | Tells whether start_color() has been called to initialise color usage |
| screen_encoding | int | |
| PyCursesWindow_Type | PyTypeObject * | Must convert to heap type |
| ModDict | PyObject * |
There is also a capsule with a C API. I'm not sure if this needs special handling wrt. PEP-489, but the _curses C API exposes three of the global variables1 directly. That said, those three variables are all guards for curses specific initialisation; it may make sense to keep these variables global; I don't know yet. The capsule C API also uses the _curses exception object (curses.error). Altering or removing the _curses C API is a breaking change and must follow the deprecation cycle of PEP-387.
Apart from the capsule C API issues, converting the remaining global variables to module state variables seem to be an easy task; most of them are used in either module functions or class methods. We can store the state in the PyCursesWindow_Type object for easy access and minimal churn.
Pitch
This is needed in order to support a per-interpreter GIL.
Previous discussion
https://github.com/ericsnowcurrently/multi-core-python/wiki/0-The-Plan
Linked PRs
Footnotes
-
initialised_setupterm,initialisedcolors, andinitialised↩
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
chgnrdv commentedon May 21, 2023
@erlend-aasland, don't mind if I work on this one? :)
erlend-aasland commentedon May 21, 2023
Sure, go ahead; I don't have time for this at the moment.
erlend-aasland commentedon May 21, 2023
There might be a WIP PR open by me. Feel free to pick up where I left.
chgnrdv commentedon May 21, 2023
@erlend-aasland, sorry, I can't find any. It's not a problem though, because I almost finished my own work and will submit a PR soon (I hope so).
erlend-aasland commentedon May 21, 2023
Nice. You can ping me and
@kumaraditya303when you're ready.erlend-aasland commentedon Jun 16, 2023
I'm not sure it is worth it isolating
_curses; is there a real use case where one would runcursesany other place than the main interpreter? See also #103092 (comment).I think we should consider just leaving it as it is.
cc. @ericsnowcurrently
ericsnowcurrently commentedon Jun 28, 2023
Yeah, the status quo is: it won't get imported in isolated subinterpreters. That should be fine.
erlend-aasland commentedon Jun 28, 2023
Yep. Closing as wont-fix.