On Mon, 2020-08-10 at 19:41 +0200, Antoine Pitrou wrote:
Le 10/08/2020 à 19:04, Sebastian Berg a écrit :
In that case, is
PyGILState_Ensure()
considered safe and appropriate API to be used within "third-party C function" (and/or NumPy API)? I used to generally think its not, but now it seems to me it should be, if the thread we are running on was previously spawned by Python?
PyGILState_Ensure()
should always be safe, regardless of who/what spawned the thread. The only limit is that it doesn't handle subinterpreters well.Yes, sorry, to be clear: I am worried about subinterpreters. Not because I feel its pressing, or because I particularly like the topic... But if I create new public API now, I don't want to have to extend it in 2 years for something I can anticipate now. At least in cases where adding the API does not hurt.
In this case, for future-proofing, you may want to take a
PyInterpreterState*
argument, because that is probably going to be how CPython approaches things (i.e. create a new API like PyGILState_Ensure(), but that knows about different interpreters).I would also recommend you chime in on https://bugs.python.org/issue15751 and describe your dilemma there.
Thanks, the main thing right now is be about passing said argument, although taking may also happen (I need to take it at one place, but that requires a complete new function in any case).
So that sounds like I should simply pass an always NULL, reserved argument for now (for the sake of passing, this will probably part of a struct in this case). And see where things go in the future.
For taking, I guess I will just defer any decision about it, if its very clear where things are going. That may require downstream to jump through small hoops later on, but maybe that is just life...
- Sebastian
(cc Eric Snow, who works on improving subinterpreters, and whom I'm not sure is on this list)
Regards
Antoine.
capi-sig mailing list -- capi-sig@python.org To unsubscribe send an email to capi-sig-leave@python.org https://mail.python.org/mailman3/lists/capi-sig.python.org/ Member address: sebastian@sipsolutions.net