|
6 | 6 | import signal
|
7 | 7 | import threading
|
8 | 8 | import unittest
|
9 |
| - |
| 9 | +from test.test_asyncio import utils as test_utils |
10 | 10 | from unittest import mock
|
11 | 11 | from unittest.mock import patch
|
12 |
| -from test.test_asyncio import utils as test_utils |
13 | 12 |
|
14 | 13 |
|
15 | 14 | def tearDownModule():
|
@@ -211,6 +210,54 @@ async def main():
|
211 | 210 | asyncio.run(main())
|
212 | 211 | self.assertTrue(policy.set_event_loop.called)
|
213 | 212 |
|
| 213 | + def test_asyncio_run_without_uncancel(self): |
| 214 | + # See https://github.com/python/cpython/issues/95097 |
| 215 | + class Task: |
| 216 | + def __init__(self, loop, coro, **kwargs): |
| 217 | + self._task = asyncio.Task(coro, loop=loop, **kwargs) |
| 218 | + |
| 219 | + def cancel(self, *args, **kwargs): |
| 220 | + return self._task.cancel(*args, **kwargs) |
| 221 | + |
| 222 | + def add_done_callback(self, *args, **kwargs): |
| 223 | + return self._task.add_done_callback(*args, **kwargs) |
| 224 | + |
| 225 | + def remove_done_callback(self, *args, **kwargs): |
| 226 | + return self._task.remove_done_callback(*args, **kwargs) |
| 227 | + |
| 228 | + @property |
| 229 | + def _asyncio_future_blocking(self): |
| 230 | + return self._task._asyncio_future_blocking |
| 231 | + |
| 232 | + def result(self, *args, **kwargs): |
| 233 | + return self._task.result(*args, **kwargs) |
| 234 | + |
| 235 | + def done(self, *args, **kwargs): |
| 236 | + return self._task.done(*args, **kwargs) |
| 237 | + |
| 238 | + def cancelled(self, *args, **kwargs): |
| 239 | + return self._task.cancelled(*args, **kwargs) |
| 240 | + |
| 241 | + def exception(self, *args, **kwargs): |
| 242 | + return self._task.exception(*args, **kwargs) |
| 243 | + |
| 244 | + def get_loop(self, *args, **kwargs): |
| 245 | + return self._task.get_loop(*args, **kwargs) |
| 246 | + |
| 247 | + |
| 248 | + async def main(): |
| 249 | + interrupt_self() |
| 250 | + await asyncio.Event().wait() |
| 251 | + |
| 252 | + def new_event_loop(): |
| 253 | + loop = self.new_loop() |
| 254 | + loop.set_task_factory(Task) |
| 255 | + return loop |
| 256 | + |
| 257 | + asyncio.set_event_loop_policy(TestPolicy(new_event_loop)) |
| 258 | + with self.assertRaises(asyncio.CancelledError): |
| 259 | + asyncio.run(main()) |
| 260 | + |
214 | 261 |
|
215 | 262 | class RunnerTests(BaseTest):
|
216 | 263 |
|
|
0 commit comments