Uh oh!
There was an error while loading. Please reload this page.
gh-123961: convert curses to a multi-phase initialization module (PEP-489) - #124965
Conversation
picnixz
commented
Oct 4, 2024
Following our discussion on the previous PR, I also changed the |
This comment was marked as resolved.
This comment was marked as resolved.
picnixz
commented
Oct 4, 2024
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!) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
left a comment
There was a problem hiding this comment.
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 |
vstinner
commented
Oct 7, 2024
importsysimportgcprint("load-unload")
import_cursesdel_cursesdelsys.modules['_curses']
gc.collect()
print("load again")
import_cursesdel_cursesdelsys.modules['_curses'] |
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Oct 8, 2024
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 |
vstinner
commented
Oct 8, 2024
It works if you run my script: |
After some tests, it appears that the REPL only calls $ read -r -d '' code <<EOMimport sysprint("load-unload")import _cursesdel _cursesdel sys.modules['_curses']print("load again")import _cursesdel _cursesdel 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 processWhen $ read -r -d '' code <<EOMimport sysimport gcprint("load-unload")import _cursesdel _cursesdel sys.modules['_curses']gc.collect()print("load again")import _cursesdel _cursesdel sys.modules['_curses']EOM
$ ./python -c "$code"
load-unload
load again |
vstinner
commented
Oct 8, 2024
Merged, thanks. That's a nice step forward for the _curses extension :-) |
vstinner
commented
Oct 8, 2024
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.cto fix reference leaks #123961