Python Glossary Русский

all Python 3Exceptionsexception

RuntimeWarning

built-in exceptions

Warns about dubious behaviour at run time.

Syntax

raise RuntimeWarning

Unlike ResourceWarning it is shown by default, but only once per source location, so inside a loop it can look as if the problem went away. The classic case in student code is coroutine ... was never awaited: the coroutine was called but never driven by await or asyncio.run, so its body never ran. Catching the warning achieves nothing; fix what triggered it.

Examples

try:
    raise RuntimeWarning
except RuntimeWarning as e:
    print(type(e).__name__)   # → RuntimeWarning

See also

Open in the full glossarydocs.python.orgReport an inaccuracy