Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError
Clint Olsen
clint.olsen at gmail.com
Fri Mar 31 20:22:06 EDT 2023
On Friday, March 31, 2023 at 4:14:51 PM UTC-7, Chris Angelico wrote:
> Okay, so that deals with the part from the subject line, leaving a
> slightly different problem: The caught exception is not of the same
> type as you were expecting. First question: Can you reproduce the
> issue on command? If so, I would recommend trying this:
>
> except BaseException as e:
> print("Got an exception!", type(e))
> print(id(type(e)))
> print(id(asyncio.CancelledError)
> except:
> print("Weird things are happening")
> import sys
> print(sys.exc_info())
> print(id(sys.exc_info()[0]))
> print(id(asyncio.CancelledError))
>
> Basically, I want to know whether (a) BaseException has changed, which
> would be a nightmare; and (b) whether asyncio.CancelledError has
> changed.
>
> This is the kind of bizarre behaviour that can happen if a module is
> reloaded, or if there are multiple versions loaded for some reason.
> But if that ISN'T what's happening, there'll have to be some other
> explanation.
Here's what I see:
Got an exception! <class 'asyncio.exceptions.CancelledError'>
8204064
8204064
Thanks,
-Clint
More information about the Python-list
mailing list