[Python] Is there any way to catch and handle infinite recursive functions that create Tkinter...

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I have a student that submitted a function like this:

    def infinite_windows():
    window = tkinter.Tk()
    infinite_windows()


    I already test things inside a try-except block. My code reports the RecursionError, but then it freezes my desktop the next time it asks for user input and I have to kill Python. The following code hangs, but only when the input() call is included:

    import tkinter

    def infinite_windows():
    window = tkinter.Tk()
    infinite_windows()

    try:
    infinite_windows()
    except Exception as e:
    print("caught the exception!")
    print(e)

    input("hi there") #hangs here


    Is there any way for me to handle this behavior and continue running Python without removing the call to input()?

    Continue reading...

Compartilhe esta Página