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

Isolate the _curses extension module #101714

Closed
Tracked by #103092
erlend-aasland opened this issue Feb 8, 2023 · 8 comments
Closed
Tracked by #103092

Isolate the _curses extension module #101714

erlend-aasland opened this issue Feb 8, 2023 · 8 comments
Labels
extension-modules C modules in the Modules dir topic-subinterpreters type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Feb 8, 2023

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

  1. initialised_setupterm, initialisedcolors, and initialised

@erlend-aasland erlend-aasland added type-feature A feature request or enhancement extension-modules C modules in the Modules dir topic-subinterpreters labels Feb 8, 2023
@chgnrdv
Copy link
Contributor

chgnrdv commented May 21, 2023

@erlend-aasland, don't mind if I work on this one? :)

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland, don't mind if I work on this one? :)

Sure, go ahead; I don't have time for this at the moment.

@erlend-aasland
Copy link
Contributor Author

There might be a WIP PR open by me. Feel free to pick up where I left.

@chgnrdv
Copy link
Contributor

chgnrdv commented 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
Copy link
Contributor Author

Nice. You can ping me and @kumaraditya303 when you're ready.

@erlend-aasland
Copy link
Contributor Author

I'm not sure it is worth it isolating _curses; is there a real use case where one would run curses any other place than the main interpreter? See also #103092 (comment).

I think we should consider just leaving it as it is.

cc. @ericsnowcurrently

@ericsnowcurrently
Copy link
Member

Yeah, the status quo is: it won't get imported in isolated subinterpreters. That should be fine.

@erlend-aasland
Copy link
Contributor Author

Yep. Closing as wont-fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir topic-subinterpreters type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

3 participants