-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hang instead of pthread_exit during interpreter shutdown (#4874)
* hang instead of pthread_exit during interpreter shutdown see python/cpython#87135 and rust-lang/rust#135929 * relnotes * fix warnings * version using pthread_cleanup_push * add tests * new attempt * clippy * comment * msrv * address review comments * update comment * add comment * try to skip test on debug builds --------- Co-authored-by: Ariel Ben-Yehuda <arielby@amazon.com> Co-authored-by: David Hewitt <mail@davidhewitt.dev>
- Loading branch information
1 parent
295e67a
commit b726d6a
Showing
5 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* PyO3 threads now hang instead of `pthread_exit` trying to acquire the GIL when the interpreter is shutting down. This mimics the [Python 3.14](https://github.com/python/cpython/issues/87135) behavior and avoids undefined behavior and crashes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sysconfig | ||
|
||
import pytest | ||
|
||
from pyo3_pytests import misc | ||
|
||
|
||
def make_loop(): | ||
# create a reference loop that will only be destroyed when the GC is called at the end | ||
# of execution | ||
start = [] | ||
cur = [start] | ||
for _ in range(1000 * 1000 * 10): | ||
cur = [cur] | ||
start.append(cur) | ||
return start | ||
|
||
|
||
# set a bomb that will explode when modules are cleaned up | ||
loopy = [make_loop()] | ||
|
||
|
||
@pytest.mark.skipif( | ||
sysconfig.get_config_var("Py_DEBUG"), | ||
reason="causes a crash on debug builds, see discussion in https://github.com/PyO3/pyo3/pull/4874", | ||
) | ||
def test_hammer_gil(): | ||
loopy.append(misc.hammer_gil_in_thread()) |