Skip to content

Commit 606ef5c

Browse files
make it->future immutable
1 parent 1afac5f commit 606ef5c

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Lib/test/test_asyncio/test_free_threading.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
threading_helper.requires_working_threading(module=True)
99

10+
def tearDownModule():
11+
asyncio._set_event_loop_policy(None)
12+
1013

1114
class TestFreeThreading:
1215
def test_all_tasks_race(self) -> None:

Modules/_asynciomodule.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,11 +1661,9 @@ FutureIter_am_send_lock_held(futureiterobject *it, PyObject **result)
16611661

16621662
PyObject *res;
16631663
FutureObj *fut = it->future;
1664+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);
16641665

16651666
*result = NULL;
1666-
if (fut == NULL) {
1667-
return PYGEN_ERROR;
1668-
}
16691667

16701668
if (fut->fut_state == STATE_PENDING) {
16711669
if (!fut->fut_blocking) {
@@ -1678,17 +1676,12 @@ FutureIter_am_send_lock_held(futureiterobject *it, PyObject **result)
16781676
return PYGEN_ERROR;
16791677
}
16801678

1681-
it->future = NULL;
1682-
Py_BEGIN_CRITICAL_SECTION(fut);
16831679
res = _asyncio_Future_result_impl(fut);
1684-
Py_END_CRITICAL_SECTION();
16851680
if (res != NULL) {
1686-
Py_DECREF(fut);
16871681
*result = res;
16881682
return PYGEN_RETURN;
16891683
}
16901684

1691-
Py_DECREF(fut);
16921685
return PYGEN_ERROR;
16931686
}
16941687

@@ -1698,7 +1691,7 @@ FutureIter_am_send(futureiterobject *it,
16981691
PyObject **result)
16991692
{
17001693
PySendResult res;
1701-
Py_BEGIN_CRITICAL_SECTION(it);
1694+
Py_BEGIN_CRITICAL_SECTION(it->future);
17021695
res = FutureIter_am_send_lock_held(it, result);
17031696
Py_END_CRITICAL_SECTION();
17041697
return res;

0 commit comments

Comments
 (0)