@@ -387,6 +387,21 @@ The exact details of this deprecation aren't too clear. It's likely that
387387the usual five-year deprecation (as specificed by :pep: `387 `) will be too
388388short, so for now, these functions will have no specific removal date.
389389
390+ Compatibility Shim for ``PyGILState_Ensure ``
391+ --------------------------------------------
392+
393+ This proposal comes with :c:func: `PyUnstable_GetDefaultInterpreterRef ` as a
394+ compatibility hack for some users of :c:func: `PyGILState_Ensure `. It is a
395+ thread-safe way to acquire a strong reference to the main (or "default")
396+ interpreter.
397+
398+ The main drawback to porting new code to :c:func: `PyThreadState_Ensure ` is that
399+ it isn't a drop-in replacement for :c:func: `!PyGILState_Ensure `, as it needs
400+ an interpreter reference argument. In some large applications, refactoring to
401+ use a :c:type: `PyInterpreterRef ` everywhere might be tricky; so, this function
402+ acts as a silver bullet for users who explicitly want to disallow support for
403+ subinterpreters.
404+
390405Specification
391406=============
392407
@@ -906,7 +921,7 @@ Example: Calling Python Without a Callback Parameter
906921There are a few cases where callback functions don't take a callback parameter
907922(``void *arg ``), so it's impossible to acquire a reference to any specific
908923interpreter. The solution to this problem is to acquire a reference to the main
909- interpreter through :c:func: `PyUnstable_InterpreterRef_GetMain `.
924+ interpreter through :c:func: `PyUnstable_GetDefaultInterpreterRef `.
910925
911926But wait, won't that break with subinterpreters, per
912927:ref: `pep-788-subinterpreters-gilstate `? Fortunately, since the callback has
@@ -919,7 +934,7 @@ interpreter here.
919934 static void
920935 call_python(void)
921936 {
922- PyInterpreterRef ref = PyUnstable_InterpreterRef_GetMain ();
937+ PyInterpreterRef ref = PyUnstable_GetDefaultInterpreterRef ();
923938 if (ref == 0) {
924939 fputs("Python has shut down.", stderr);
925940 return;
0 commit comments