Skip to content

Convert _ctypes extension module to multi-phase init #117142

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

Closed
2 tasks done
Tracked by #103092
neonene opened this issue Mar 22, 2024 · 8 comments
Closed
2 tasks done
Tracked by #103092

Convert _ctypes extension module to multi-phase init #117142

neonene opened this issue Mar 22, 2024 · 8 comments
Labels
extension-modules C modules in the Modules dir topic-subinterpreters type-feature A feature request or enhancement

Comments

@neonene
Copy link
Contributor

neonene commented Mar 22, 2024

Feature or enhancement

Proposal:

This issue is available to keep track of PRs, following the heap type conversion completed at #114314.

TODO:

  • [ ] Make free_list in malloc_closure.c per-module variables. rejected
  • Fix intentional memory leaks of StgInfo during a finalization: comment.
  • Enable Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED(DONE): comment.
    FUTURE?: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED after a compatible PyGILState_Ensure() is introduced, see also the links below.

Links to documents:

Links to previous discussion of this feature:

Linked PRs

@neonene
Copy link
Contributor Author

neonene commented May 8, 2024

Could anyone add this open issue to the base issue's todo (port _ctypes branch) as a checked (finished) leaf? Thanks.

@ericsnowcurrently
Copy link
Member

@encukou, this is done now, right?

@encukou
Copy link
Member

encukou commented May 23, 2024

I'll wait for more green buildbots before merging the 3.13 backport. Then it'll be done :)

@encukou encukou closed this as completed May 30, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Subinterpreters May 30, 2024
@ericsnowcurrently
Copy link
Member

Unless I was looking at an old main HEAD, _ctypes is still has py_mod_multiple_interpreters set to Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED. Is there are reason we haven't set it to Py_MOD_PER_INTERPRETER_GIL_SUPPORTED?

CC @neonene

@neonene
Copy link
Contributor Author

neonene commented May 30, 2024

In my understanding of #117181 (comment), the closure_fcn function in callbacks.c needs a new compatible PyGILState_Ensure() faimily like #59956 (comment) to enable Py_MOD_PER_INTERPRETER_GIL_SUPPORTED?

Issue #55124 in 2011 has an experimantal patch: https://bugs.python.org/file20417/gilstateinterp.patch

@encukou
Copy link
Member

encukou commented May 31, 2024

Also mmap-based closure allocation needs a mutex, and I don't know how thread-safe the libffi API is. There might be other things.

@ericsnowcurrently
Copy link
Member

FYI, PyGILState_Ensure() should work fine with subinterpreters, as of 3.12. It was necessary to fix that for per-interpreter GIL.

@ericsnowcurrently
Copy link
Member

Regarding mmap and libffi, aren't those resolved for free-threading builds?

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

4 participants