[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-14 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Roland Netzsch


Change by Roland Netzsch :


--
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

I don't follow what reliability guarantee are you requesting.

A cite from task.cancel() docstring:

> Request that this task cancel itself.

This arranges for a CancelledError to be thrown into the
wrapped coroutine on the next cycle through the event loop.
The coroutine then has a chance to clean up or even deny
the request using try/except/finally.

Unlike Future.cancel, this does not guarantee that the
task will be cancelled: the exception might be caught and
acted upon, delaying cancellation of the task or preventing
cancellation completely.  The task may also return a value or
raise a different exception.

Immediately after this method is called, Task.cancelled() will
not return True (unless the task was already cancelled).  A
task will be marked as cancelled when the wrapped coroutine
terminates with a CancelledError exception (even if cancel()
was not called).

task.cancelled() returns True for canceled and finished tasks, but 
task.cancel() is a request for cancellation. The requested task needs some time 
to gracefully finish itself.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Roland Netzsch


Roland Netzsch  added the comment:

So there is no way to reliably find out whether a task has been cancelled by 
calling Task.cancelled()?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

This is the expected behavior.

asyncio.ensure_future() returns not a future but a task for your case.
Task cancellation requires at least one context switch to finish the task.

P.S.
I suggest replacing `asyncio.ensure_future()` with `asyncio.create_task()` to 
avoid confusion.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Roland Netzsch


Roland Netzsch  added the comment:

Python-Version:

[stuxcrystal@caprica ~]$ python3.7 --version
Python 3.7.3


Additional Notes:
Distribution: Fedora 30 (Workstation Edition)
Kernel: x86_64 Linux 5.0.9-301.fc30.x86_64

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37202] Future.cancelled is not set to true immediately after calling Future.cancel

2019-06-08 Thread Roland Netzsch


New submission from Roland Netzsch :

The attached file produces the following output:

wait is still running
wait is not set to cancelled!
Awaiting cancelled future produced a CancelledError.

A look a the documentation does not suggest a need to await the future in order 
to make sure the cancelled-flag is being set.

--
components: asyncio
files: test.py
messages: 345029
nosy: Roland Netzsch, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Future.cancelled is not set to true immediately after calling 
Future.cancel
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48405/test.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com