Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AttributeError: 'Task' object has no attribute 'uncancel'. Did you mean: 'cancel'? when the asyncioloop.set_task_factory factory returns aasyncio.Future-compatible object #95097

Closed
Labels
3.11only security fixes3.12only security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error
@graingert

Description

@graingert

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

No one assigned

    Labels

    3.11only security fixes3.12only security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp