diff options
author | Yury Selivanov <yury@magic.io> | 2017-06-11 13:49:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-11 13:49:18 (GMT) |
commit | 7ce1c6fb579a01bb184224a10019039fde9c8eaf (patch) | |
tree | cfae34038438eb189d445bcd6391c9c19607baf7 /Modules/_asynciomodule.c | |
parent | 36ff451ebae41f09560bff582c95946474d898f8 (diff) | |
download | cpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.zip cpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.tar.gz cpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.tar.bz2 |
bpo-30508: Don't log exceptions if Task/Future "cancel()" method called (#2050)
Diffstat (limited to 'Modules/_asynciomodule.c')
-rw-r--r-- | Modules/_asynciomodule.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 150ca19..b8a88e6 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -306,6 +306,8 @@ future_add_done_callback(FutureObj *fut, PyObject *arg) static PyObject * future_cancel(FutureObj *fut) { + fut->fut_log_tb = 0; + if (fut->fut_state != STATE_PENDING) { Py_RETURN_FALSE; } @@ -639,6 +641,17 @@ FutureObj_get_log_traceback(FutureObj *fut) } } +static int +FutureObj_set_log_traceback(FutureObj *fut, PyObject *val) +{ + int is_true = PyObject_IsTrue(val); + if (is_true < 0) { + return -1; + } + fut->fut_log_tb = is_true; + return 0; +} + static PyObject * FutureObj_get_loop(FutureObj *fut) { @@ -883,7 +896,8 @@ static PyMethodDef FutureType_methods[] = { {"_callbacks", (getter)FutureObj_get_callbacks, NULL, NULL}, \ {"_result", (getter)FutureObj_get_result, NULL, NULL}, \ {"_exception", (getter)FutureObj_get_exception, NULL, NULL}, \ - {"_log_traceback", (getter)FutureObj_get_log_traceback, NULL, NULL}, \ + {"_log_traceback", (getter)FutureObj_get_log_traceback, \ + (setter)FutureObj_set_log_traceback, NULL}, \ {"_source_traceback", (getter)FutureObj_get_source_traceback, NULL, NULL}, static PyGetSetDef FutureType_getsetlist[] = { @@ -1569,6 +1583,8 @@ static PyObject * _asyncio_Task_cancel_impl(TaskObj *self) /*[clinic end generated code: output=6bfc0479da9d5757 input=13f9bf496695cb52]*/ { + self->task_log_tb = 0; + if (self->task_state != STATE_PENDING) { Py_RETURN_FALSE; } |