Reputation: 27
Feeling really stupid right now. I opened a python file in my Windows console and the file raised an error (such as TypeError
, AttributeError
, etc.) and the console won't work anymore so I have to close it and open a new window everytime I get an error. There should be a shortcut or something to exit but Ctrl+C
doesn't work. I have Windows 10 and Python 3.6.
When I run my file in the console happens this:
C:\Users\...path...>python my_file.py
Traceback (most recent call last):
File "C:\Users\...path...\my_file.py", line 74,
...stuff...
AttributeError: my error
And after this I can't do anything. If someone could help.
Upvotes: 0
Views: 411
Reputation: 35986
On an unhandled exception, a Python program normally quits, and you get the console prompt back. If yours doesn't, it means that it hangs instead.
If Ctrl-C doesn't work, you can force-kill a Windows console program with Ctrl-Break.
But you really should find out why it hangs, as it's not normal. My guess is you're swallowing all exceptions somewhere, e.g. with an unqualified except:
which is strongly discouraged exactly for this reason.
Upvotes: 1
Reputation: 5404
May be because of bug/error your program become freeze. Please try to use exception handling. An example :
try:
your_codes()
except Exception as ex:
print(ex)
This is just an example of exception handling. You can do it in much better (but complicated!) approach. You can read this doc.
Upvotes: 0