From 40c572550256d756e5e6d52d6b61573afe932e32 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 6 Oct 2022 15:45:59 +0000 Subject: [PATCH] gh-96078: os.sched_yield release the GIL while calling sched_yield(2). --- .../2022-10-06-15-45-57.gh-issue-96078.fS-6mU.rst | 2 ++ Modules/posixmodule.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-10-06-15-45-57.gh-issue-96078.fS-6mU.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-10-06-15-45-57.gh-issue-96078.fS-6mU.rst b/Misc/NEWS.d/next/Core and Builtins/2022-10-06-15-45-57.gh-issue-96078.fS-6mU.rst new file mode 100644 index 00000000000000..d1f949c6e13adc --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-10-06-15-45-57.gh-issue-96078.fS-6mU.rst @@ -0,0 +1,2 @@ +:func:`os.sched_yield` now release the GIL while calling sched_yield(2). +Patch by Dong-hee Na. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index cbdc259737583c..a72d57771c2294 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7075,8 +7075,13 @@ static PyObject * os_sched_yield_impl(PyObject *module) /*[clinic end generated code: output=902323500f222cac input=e54d6f98189391d4]*/ { - if (sched_yield()) + int result; + Py_BEGIN_ALLOW_THREADS + result = sched_yield(); + Py_END_ALLOW_THREADS + if (result < 0) { return posix_error(); + } Py_RETURN_NONE; }