Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Feature or enhancement
PEP 703 in large part relies on replacing the GIL with fine grained per-object locks. The primary way to acquire and release these locks is through the critical section API (#111569). It would be helpful if argument clinic could auto generate the API calls in the binding code when specified.
For example, thebufferedio.c will require per-object locking around most calls for thread-safety in--disable-gil builds.
As an example, the_io._Buffered.close function is written as:
cpython/Modules/_io/bufferedio.c
Lines 523 to 529 in6f09f69
| /*[clinic input] | |
| _io._Buffered.close | |
| [clinic start generated code]*/ | |
| staticPyObject* | |
| _io__Buffered_close_impl(buffered*self) | |
| /*[clinic end generated code: output=7280b7b42033be0c input=d20b83d1ddd7d805]*/ |
We might add a@critical_section directive to designate that argument clinic should generatePy_BEGIN_CRITICAL_SECTION() andPy_END_CRITICAL_SECTION() in the binding code before calling_io__Buffered_close_impl.
/*[clinic input]@critical_section_io._Buffered.close[clinic start generated code]*/staticPyObject*_io__Buffered_close_impl(buffered*self)/*[clinic end generated code: output=7280b7b42033be0c input=d20b83d1ddd7d805]*/
The generated binding code inbufferedio.c.h would then look like:
staticPyObject*_io__Buffered_close(buffered*self,PyObject*Py_UNUSED(ignored)){PyObject*return_value=NULL;Py_BEGIN_CRITICAL_SECTION(self);return_value=_io__Buffered_close_impl(self);Py_END_CRITICAL_SECTION();returnreturn_value;}
Note thatPy_BEGIN/END_CRITICAL_SECTION() are no-ops in the default build.