Skip to content

Commit 3f54668

Browse files
add more tests
1 parent 5f94aa1 commit 3f54668

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

Lib/test/test_free_threading/test_async_generators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def drive():
2626
values.append(e.value)
2727
except StopAsyncIteration:
2828
break
29-
except (RuntimeError, ValueError):
29+
except RuntimeError:
3030
# Another thread is currently driving the generator.
3131
continue
3232

@@ -58,7 +58,7 @@ def worker():
5858
except StopIteration as e:
5959
# The generator received the exception and yielded again.
6060
delivered.append(e.value)
61-
except (RuntimeError, ValueError):
61+
except RuntimeError:
6262
# Another thread is currently driving the generator.
6363
pass
6464

@@ -89,7 +89,7 @@ def worker():
8989
except StopAsyncIteration:
9090
# The generator was already closed.
9191
pass
92-
except (RuntimeError, ValueError):
92+
except RuntimeError:
9393
# Another thread is currently driving the generator.
9494
pass
9595

Objects/genobject.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,15 +1960,13 @@ async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result)
19601960
FT_ATOMIC_STORE_INT8_RELAXED(gen->ag_closed, 1);
19611961
}
19621962

1963-
FT_ATOMIC_STORE_INT8_RELAXED(gen->ag_running_async, 0);
19641963
return NULL;
19651964
}
19661965

19671966
if (_PyAsyncGenWrappedValue_CheckExact(result)) {
19681967
/* async yield */
19691968
_PyGen_SetStopIterationValue(((_PyAsyncGenWrappedValue*)result)->agw_val);
19701969
Py_DECREF(result);
1971-
FT_ATOMIC_STORE_INT8_RELAXED(gen->ag_running_async, 0);
19721970
return NULL;
19731971
}
19741972

@@ -2047,6 +2045,7 @@ do_send:;
20472045

20482046
if (result == NULL) {
20492047
FT_ATOMIC_STORE_INT8_RELAXED(o->ags_state, AWAITABLE_STATE_CLOSED);
2048+
FT_ATOMIC_STORE_INT8_RELEASE(o->ags_gen->ag_running_async, 0);
20502049
}
20512050

20522051
return result;
@@ -2107,7 +2106,7 @@ do_throw:;
21072106

21082107
if (result == NULL) {
21092108
FT_ATOMIC_STORE_INT8_RELAXED(o->ags_state, AWAITABLE_STATE_CLOSED);
2110-
FT_ATOMIC_STORE_INT8_RELAXED(o->ags_gen->ag_running_async, 0);
2109+
FT_ATOMIC_STORE_INT8_RELEASE(o->ags_gen->ag_running_async, 0);
21112110
}
21122111

21132112
return result;
@@ -2399,14 +2398,14 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
23992398

24002399
if (FT_ATOMIC_LOAD_INT8_RELAXED(o->agt_gen->ag_closed)) {
24012400
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2402-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2401+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
24032402
PyErr_SetNone(PyExc_StopAsyncIteration);
24042403
return NULL;
24052404
}
24062405

24072406
if (arg != Py_None) {
24082407
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_INIT);
2409-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2408+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
24102409
PyErr_SetString(PyExc_RuntimeError, NON_INIT_CORO_MSG);
24112410
return NULL;
24122411
}
@@ -2439,7 +2438,11 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
24392438
do_send:
24402439
retval = gen_send((PyObject *)gen, arg);
24412440
if (o->agt_typ) {
2442-
return async_gen_unwrap_value(o->agt_gen, retval);
2441+
retval = async_gen_unwrap_value(o->agt_gen, retval);
2442+
if (retval == NULL) {
2443+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
2444+
}
2445+
return retval;
24432446
} else {
24442447
/* aclose() mode */
24452448
if (retval) {
@@ -2457,15 +2460,15 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
24572460
}
24582461

24592462
yield_close:
2460-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2461-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2463+
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2464+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
24622465
PyErr_SetString(
24632466
PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG);
24642467
return NULL;
24652468

24662469
check_error:
2467-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
24682470
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2471+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
24692472
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
24702473
PyErr_ExceptionMatches(PyExc_GeneratorExit))
24712474
{
@@ -2524,22 +2527,22 @@ do_throw:;
25242527
retval = async_gen_unwrap_value(o->agt_gen, retval);
25252528
if (retval == NULL) {
25262529
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2527-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2530+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
25282531
}
25292532
return retval;
25302533
}
25312534
else {
25322535
/* aclose() mode */
25332536
if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) {
25342537
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2535-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2538+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
25362539
Py_DECREF(retval);
25372540
PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG);
25382541
return NULL;
25392542
}
25402543
if (retval == NULL) {
25412544
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_state, AWAITABLE_STATE_CLOSED);
2542-
FT_ATOMIC_STORE_INT8_RELAXED(o->agt_gen->ag_running_async, 0);
2545+
FT_ATOMIC_STORE_INT8_RELEASE(o->agt_gen->ag_running_async, 0);
25432546
}
25442547
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
25452548
PyErr_ExceptionMatches(PyExc_GeneratorExit))

0 commit comments

Comments
 (0)