Repository navigation
bpo-36475: Finalize PyEval_AcquireLock() and PyEval_AcquireThread() properly #12667
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
Changes from 4 commits
4f6b32d
2c02944
b8a1690
f2337be
5daac23
d14cedb
4e1d820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1080,9 +1080,27 @@ All of the following functions must be called after :c:func:`Py_Initialize`. | |
| *tstate*, which should not be *NULL*. The lock must have been created earlier. | ||
| If this thread already has the lock, deadlock ensues. | ||
|
|
||
| .. note:: | ||
| Calling this function from a thread when the runtime is finalizing | ||
| will terminate the thread, even if the thread was not created by Python. | ||
| You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to | ||
| check if the interpreter is in process of being finalized before calling | ||
| this function to avoid unwanted termination. | ||
|
|
||
| .. versionchanged:: 3.8 | ||
| Updated to be consistent with :c:func:`PyEval_RestoreThread`, | ||
| :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`, | ||
| and terminate the current thread if called while the interpreter is finalizing. | ||
|
|
||
| :c:func:`PyEval_RestoreThread` is a higher-level function which is always | ||
| available (even when threads have not been initialized). | ||
|
|
||
| .. note:: | ||
| Calling this function from a thread when the runtime is finalizing | ||
| will terminate the thread, even if the thread was not created by Python. | ||
| You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vstinner Are you aware of any particular reason for (That can be broken out to a separate issue, though - it doesn't need to be resolved here)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. Feel free to open an issue to propose to make it public if you want. In my PR #12934, I modified the internal _Py_CURRENTLY_FINALIZING() macro to add a runtime parameter :-) (PR currently under review.) |
||
| check if the interpreter is in process of being finalized before calling | ||
| this function to avoid unwanted termination. | ||
|
|
||
|
nanjekyejoannah marked this conversation as resolved.
Outdated
|
||
| .. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate) | ||
|
|
||
|
|
@@ -1106,6 +1124,18 @@ All of the following functions must be called after :c:func:`Py_Initialize`. | |
| :c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread` | ||
| instead. | ||
|
|
||
| .. note:: | ||
| Calling this function from a thread when the runtime is finalizing | ||
| will terminate the thread, even if the thread was not created by Python. | ||
| You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to | ||
| check if the interpreter is in process of being finalized before calling | ||
| this function to avoid unwanted termination. | ||
|
|
||
| .. versionchanged:: 3.8 | ||
| Updated to be consistent with :c:func:`PyEval_RestoreThread`, | ||
| :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`, | ||
| and terminate the current thread if called while the interpreter is finalizing. | ||
|
|
||
|
|
||
| .. c:function:: void PyEval_ReleaseLock() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| :c:func:`PyEval_AcquireLock` and :c:func:`PyEval_AcquireThread` now | ||
| terminate the current thread if called while the interpreter is | ||
| finalizing, making them consistent with :c:func:`PyEval_RestoreThread`, | ||
| :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended up with two copies of this note.