Prevent a console app from closing when not invoked from an existing terminal?
There are many variants on this kind of question. However I am specifically after a way to prevent a console application in Python from closing when it is not invoked from a terminal (or other console, as it may be called on Windows). An example where this could occur is double clicking a .py file from the Windows explorer. Typically I use something like the following code snippet, but it has the unfortunate side effect of operating even if the application is invoked from an existing terminal: def press_any_key(): if os.name == "nt": os.system("pause") atexit.register(press_any_key) It's also