Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
https://docs.python.org/3.11/library/asyncio-eventloop.html#asyncio.loop.set_task_factory is documented as: "The callable must return aasyncio.Future-compatible object." however a number of apis now assume tasks have anuncancel() method:
importasyncioimportsignalimportosclassTask:def__init__(self,loop,coro,**kwargs):self._task=asyncio.Task(coro,loop=loop,**kwargs)defcancel(self,*args,**kwargs):returnself._task.cancel(*args,**kwargs)defadd_done_callback(self,*args,**kwargs):returnself._task.add_done_callback(*args,**kwargs)defremove_done_callback(self,*args,**kwargs):returnself._task.remove_done_callback(*args,**kwargs)@propertydef_asyncio_future_blocking(self):returnself._task._asyncio_future_blockingdefresult(self,*args,**kwargs):returnself._task.result(*args,**kwargs)defdone(self,*args,**kwargs):returnself._task.done(*args,**kwargs)defcancelled(self,*args,**kwargs):returnself._task.cancelled(*args,**kwargs)defexception(self,*args,**kwargs):returnself._task.exception(*args,**kwargs)defget_loop(self,*args,**kwargs):returnself._task.get_loop(*args,**kwargs)asyncdefamain():os.kill(os.getpid(),signal.SIGINT)awaitasyncio.Event().wait()classMyPolicy(asyncio.DefaultEventLoopPolicy):defnew_event_loop(self,*args,**kwargs):loop=super().new_event_loop(*args,**kwargs)loop.set_task_factory(Task)returnloopasyncio.set_event_loop_policy(MyPolicy())try:asyncio.run(amain())exceptKeyboardInterrupt:print("ok!")
results in:
$ python3.10 demo.pyok!$ python3.11 demo.pyTraceback (most recent call last): File"/usr/lib/python3.11/asyncio/runners.py", line120, inrunreturnself._loop.run_until_complete(task)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/usr/lib/python3.11/asyncio/base_events.py", line650, inrun_until_completereturn future.result()^^^^^^^^^^^^^^^ File"/home/graingert/demo.py", line24, inresultreturnself._task.result(*args,**kwargs)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/home/graingert/demo.py", line41, inamainawait asyncio.Event().wait() File"/usr/lib/python3.11/asyncio/locks.py", line213, inwaitawait futasyncio.exceptions.CancelledErrorDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File"/home/graingert/demo.py", line52, in<module> asyncio.run(amain()) File"/usr/lib/python3.11/asyncio/runners.py", line187, inrunreturn runner.run(main)^^^^^^^^^^^^^^^^ File"/usr/lib/python3.11/asyncio/runners.py", line122, inrunifself._interrupt_count>0and task.uncancel()==0:^^^^^^^^^^^^^AttributeError:'Task' object has no attribute 'uncancel'. Did you mean: 'cancel'?
Your environment
- CPython versions tested on: 3.10, 3.11.0b4,a6daaf2
- Operating system and architecture:
Metadata
Metadata
Assignees
Labels
Projects
Status
Done