-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
gh-123961: convert curses
to a multi-phase initialization module (PEP-489)
#124965
Conversation
Following our discussion on the previous PR, I also changed the |
This comment was marked as resolved.
This comment was marked as resolved.
I'm really un-sure of how free-threaded builds with multi-phase initialization would interact with capsule objects. So I'd happy if any free-threaded expert could help me here. Here are some questions (and we may perhaps address them in separate PRs):
cc @colesbury (I don't know other free-threaded experts but feel free to delegate the question to anyone who knows about the topic if you don't have enough time!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to add a global variable to prevent having more than 1 instance at the same time?
Here's the output, do you think it's good enough? >>> import sys
...
>>> import _curses as curses1
>>> del sys.modules['_curses']
...
>>> import _curses as curses2
...
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
import _curses as curses2
ImportError: module 'curses' can only be loaded once per process |
import sys
import gc
print("load-unload")
import _curses
del _curses
del sys.modules['_curses']
gc.collect()
print("load again")
import _curses
del _curses
del sys.modules['_curses'] |
I'm not sure it works. Even if I do this it still tells me that the curses module cannot be loaded more than once per process. The cursesmodule_free() does not seem to be called even if |
It works if you run my script:
|
After some tests, it appears that the REPL only calls $ read -r -d '' code << EOM
import sys
print("load-unload")
import _curses
del _curses
del sys.modules['_curses']
print("load again")
import _curses
del _curses
del sys.modules['_curses']
EOM
$ ./python -c "$code"
load-unload
load again
Traceback (most recent call last):
File "<string>", line 9, in <module>
import _curses
ImportError: module 'curses' can only be loaded once per process When $ read -r -d '' code << EOM
import sys
import gc
print("load-unload")
import _curses
del _curses
del sys.modules['_curses']
gc.collect()
print("load again")
import _curses
del _curses
del sys.modules['_curses']
EOM
$ ./python -c "$code"
load-unload
load again |
Merged, thanks. That's a nice step forward for the _curses extension :-) |
Python no longer leaks at exit:
Python 3.13 for comparison:
|
I think this is the very last PR for this task, conditioned to some final cleanups just for macro readability and comments.
_cursesmodule.c
to fix reference leaks #123961