[Python] What type of message "Exception ignored in" is?

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    Here's code:

    def g():
    try:
    yield 1
    yield 2
    yield 3
    except GeneratorExit:
    yield 4

    gen = g()
    print(gen.__next__())


    If you run it you'll see:

    1
    Exception ignored in: <generator object g at 0x00000216BB546A98>
    RuntimeError: generator ignored GeneratorExit


    I understand what happened, but I can't find what type of message this warning is.

    Looks like it's not logging warning (I can't remove it setting logging level). It's also not warnings warning (It doesn't look like what we get when call warnings.warn).

    I thought it can be associated with exception, but I can't catch it with sys.excepthook, while msg itself disappears:

    import sys

    def hook(exc_type, exc_val, tb):
    print(exc_type, exc_val, tb) # Nothing prints, while msg disappear

    sys.excepthook = hook


    How can I catch this warning?

    How can I manually create this type of warning?

    Continue reading...

Compartilhe esta Página