-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
import warnings
import asyncio
async def spam():
with warnings.catch_warnings(record=True) as ws:
await asyncio.sleep(0.1)
w = Warning("12345")
warnings.warn(w)
assert w in (ww.message for ww in ws)
async def ham():
with warnings.catch_warnings(record=True) as ws:
await asyncio.sleep(0.2)
async def main():
await asyncio.gather(spam(), ham())
asyncio.run(main())Despite technically being documented (https://docs.python.org/3/library/warnings.html#warnings.catch_warnings), this is very error-prone, surprising and not at all useful. The warnings module should probably use contextvars to manage the warning handler.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error