mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
Python 3.10 improvements.
The coroutines results are now relayed back via PyIter_Send() and no longer obtainable via _PyGen_FetchStopIterationValue(). This means that our kore.gather() would not be able to return any values from any of the coroutines it governed. Fix this by saving the object returned in PyIter_Send() and using it later in pygather_reap_coro().
This commit is contained in:
parent
30c8652534
commit
fd94fba3c7
21
src/python.c
21
src/python.c
@ -1108,8 +1108,8 @@ python_coro_run(struct python_coro *coro)
|
||||
*/
|
||||
res = PyIter_Send(coro->obj, NULL, &item);
|
||||
#endif
|
||||
|
||||
if (item == NULL || res == PYGEN_ERROR) {
|
||||
Py_XDECREF(item);
|
||||
if (coro->gatherop == NULL && PyErr_Occurred() &&
|
||||
PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
||||
PyErr_Fetch(&type, &coro->result, &traceback);
|
||||
@ -1128,11 +1128,13 @@ python_coro_run(struct python_coro *coro)
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX >= 0x030A0000
|
||||
if (res == PYGEN_RETURN) {
|
||||
Py_XDECREF(item);
|
||||
coro->result = item;
|
||||
coro_running = NULL;
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (item == Py_None) {
|
||||
Py_DECREF(item);
|
||||
@ -4497,6 +4499,9 @@ pygather_reap_coro(struct pygather_op *op, struct python_coro *reap)
|
||||
{
|
||||
struct pygather_coro *coro;
|
||||
struct pygather_result *result;
|
||||
#if PY_VERSION_HEX >= 0x030A0000
|
||||
PyObject *type, *traceback;
|
||||
#endif
|
||||
|
||||
TAILQ_FOREACH(coro, &op->coroutines, list) {
|
||||
if (coro->coro->id == reap->id)
|
||||
@ -4513,10 +4518,22 @@ pygather_reap_coro(struct pygather_op *op, struct python_coro *reap)
|
||||
result = kore_pool_get(&gather_result_pool);
|
||||
result->obj = NULL;
|
||||
|
||||
#if PY_VERSION_HEX < 0x030A0000
|
||||
if (_PyGen_FetchStopIterationValue(&result->obj) == -1) {
|
||||
result->obj = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
}
|
||||
#else
|
||||
if (PyErr_Occurred()) {
|
||||
Py_XDECREF(coro->coro->result);
|
||||
PyErr_Fetch(&type, &coro->coro->result, &traceback);
|
||||
Py_DECREF(type);
|
||||
Py_XDECREF(traceback);
|
||||
}
|
||||
|
||||
result->obj = coro->coro->result;
|
||||
Py_INCREF(result->obj);
|
||||
#endif
|
||||
|
||||
TAILQ_INSERT_TAIL(&op->results, result, list);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user