parent
ddcfee18b4
commit
5bc9b70e86
|
|
@ -503,7 +503,7 @@ cancel() {
|
|||
--_chain->_num_awaiting_tasks;
|
||||
return true;
|
||||
}
|
||||
else if (must_cancel || _fut_waiter != nullptr) {
|
||||
else if (_generator != nullptr && (must_cancel || _fut_waiter != nullptr)) {
|
||||
// We may be polling an external future, so we still need to throw a
|
||||
// CancelledException and allow it to be caught.
|
||||
if (must_cancel) {
|
||||
|
|
|
|||
|
|
@ -133,13 +133,29 @@ def test_future_wait_cancel():
|
|||
fut.result()
|
||||
|
||||
|
||||
def test_task_cancel():
|
||||
def test_task_remove():
|
||||
task_mgr = core.AsyncTaskManager.get_global_ptr()
|
||||
task = core.PythonTask(lambda task: task.done)
|
||||
task_mgr.add(task)
|
||||
|
||||
assert not task.done()
|
||||
task_mgr.remove(task)
|
||||
assert not task.is_alive()
|
||||
assert task.done()
|
||||
assert task.cancelled()
|
||||
|
||||
with pytest.raises(CancelledError):
|
||||
task.result()
|
||||
|
||||
|
||||
def test_task_cancel():
|
||||
task_mgr = core.AsyncTaskManager.get_global_ptr()
|
||||
task = core.PythonTask(lambda task: task.done)
|
||||
task_mgr.add(task)
|
||||
|
||||
assert not task.done()
|
||||
task.cancel()
|
||||
assert not task.is_alive()
|
||||
assert task.done()
|
||||
assert task.cancelled()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue