summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/asyncio-eventloop.rst6
-rw-r--r--Lib/asyncio/events.py3
-rw-r--r--Lib/test/test_asyncio/test_events.py8
-rw-r--r--Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst1
4 files changed, 14 insertions, 4 deletions
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
index 9bc7a40..e635cba 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -867,6 +867,12 @@ Handle
Cancel the call. If the callback is already canceled or executed,
this method has no effect.
+ .. method:: cancelled()
+
+ Return ``True`` if the call was cancelled.
+
+ .. versionadded:: 3.7
+
Event loop examples
-------------------
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index c2663c5..270a5e4 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -117,6 +117,9 @@ class Handle:
self._callback = None
self._args = None
+ def cancelled(self):
+ return self._cancelled
+
def _run(self):
try:
self._callback(*self._args)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 0ea9c08..5394ddf 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2305,10 +2305,10 @@ class HandleTests(test_utils.TestCase):
h = asyncio.Handle(callback, args, self.loop)
self.assertIs(h._callback, callback)
self.assertIs(h._args, args)
- self.assertFalse(h._cancelled)
+ self.assertFalse(h.cancelled())
h.cancel()
- self.assertTrue(h._cancelled)
+ self.assertTrue(h.cancelled())
def test_callback_with_exception(self):
def callback():
@@ -2494,11 +2494,11 @@ class TimerTests(unittest.TestCase):
h = asyncio.TimerHandle(when, callback, args, mock.Mock())
self.assertIs(h._callback, callback)
self.assertIs(h._args, args)
- self.assertFalse(h._cancelled)
+ self.assertFalse(h.cancelled())
# cancel
h.cancel()
- self.assertTrue(h._cancelled)
+ self.assertTrue(h.cancelled())
self.assertIsNone(h._callback)
self.assertIsNone(h._args)
diff --git a/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst b/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst
new file mode 100644
index 0000000..a26aca3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst
@@ -0,0 +1 @@
+Add a ``cancelled()`` method to :class:`asyncio.Handle`. Patch by Marat Sharafutdinov.