mirror of https://git.kore.io/kore.git
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);
|
res = PyIter_Send(coro->obj, NULL, &item);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (item == NULL || res == PYGEN_ERROR) {
|
if (item == NULL || res == PYGEN_ERROR) {
|
||||||
|
Py_XDECREF(item);
|
||||||
if (coro->gatherop == NULL && PyErr_Occurred() &&
|
if (coro->gatherop == NULL && PyErr_Occurred() &&
|
||||||
PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
||||||
PyErr_Fetch(&type, &coro->result, &traceback);
|
PyErr_Fetch(&type, &coro->result, &traceback);
|
||||||
|
@ -1128,11 +1128,13 @@ python_coro_run(struct python_coro *coro)
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030A0000
|
||||||
if (res == PYGEN_RETURN) {
|
if (res == PYGEN_RETURN) {
|
||||||
Py_XDECREF(item);
|
coro->result = item;
|
||||||
coro_running = NULL;
|
coro_running = NULL;
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (item == Py_None) {
|
if (item == Py_None) {
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
|
@ -4497,6 +4499,9 @@ pygather_reap_coro(struct pygather_op *op, struct python_coro *reap)
|
||||||
{
|
{
|
||||||
struct pygather_coro *coro;
|
struct pygather_coro *coro;
|
||||||
struct pygather_result *result;
|
struct pygather_result *result;
|
||||||
|
#if PY_VERSION_HEX >= 0x030A0000
|
||||||
|
PyObject *type, *traceback;
|
||||||
|
#endif
|
||||||
|
|
||||||
TAILQ_FOREACH(coro, &op->coroutines, list) {
|
TAILQ_FOREACH(coro, &op->coroutines, list) {
|
||||||
if (coro->coro->id == reap->id)
|
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 = kore_pool_get(&gather_result_pool);
|
||||||
result->obj = NULL;
|
result->obj = NULL;
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX < 0x030A0000
|
||||||
if (_PyGen_FetchStopIterationValue(&result->obj) == -1) {
|
if (_PyGen_FetchStopIterationValue(&result->obj) == -1) {
|
||||||
result->obj = Py_None;
|
result->obj = Py_None;
|
||||||
Py_INCREF(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);
|
TAILQ_INSERT_TAIL(&op->results, result, list);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue