I have a massive loop that I am trying to debug in VS Code and running my python app in.
I keep hitting this AttributeError and it pauses the debugger which I DON'T want it to do. I want to bypass it and let it finish (which it does without debugger running).
The error:
Exception has occurred: AttributeError (note: full exception trace is shown but execution is paused at: )
I really don't want to hit F5 a billion times as I am trying to get to near the end of my program to see whatcertain variables in my Panda's DataFrame are. Is this possible?
Related
This is my first time coding and Python seems to be a pretty easy language. However, I am running into an issue.
I am getting SNS topic attributes from AWS and it returns quite a few results. It stalls and gives an internal error -- I have researched the try/except statement and so far I have been able to use it to clear the error. How do I get the script to continue after the error has been cleared?
In my project that based on asyncio and asyncio tcp connections that debugs with PyCharm debugger I got very and very very absurd errors.
If I put breakpoint on code after running, the breakpoint never fires.
But breakpoints fires if breakpoint has been put before starting program.
But in some cases the firing on breakpoints causes strange errors (if paused on breakpoint and resumed).
The next exceptions I remarked:
TypeError: 'coroutine' object not callable
SystemError: unknown opcode
First exception is very rare. Can be raised in any place on code and unrepeatable.
Second exception I remarked the first time recently. This is repeatable in my code. The function where I put breakpoint is function in async task (asyncio.Task). I can't repeat from scratch. But I think the type of exception (unknown opcode??? O_O) should make you think.
Besides! The exception vanished if I change the code: for example I added the a = 0 line. Exception not raised after. The deleting a = 0 will return this exception again.
Is this error of kind of esoteric errors?
I think the PyCharm debugger conflicts with asnycio.
Or maybe I doing something wrong?
Unknown opcode can be any line of code in the function where breakpoint put. Repeats in specific places in code.
This exception also can be at line, but also inside another function. Very rare and unreproducible
which version of python you use? There is new debugger for python3.6 based on inserting opcodes before starting process. You can find some more info in this repo https://github.com/Elizaveta239/frame-eval
The logging module does it's job to report things occurring before the application crash. But somehow it missed the most important part: it doesn't log the error that crash the app, which I find surprising (I'm a beginner).
I know I could print these errors using the try except statement. But it's a rather complicate step to merely print the error which crash the app (it requires to modifies the code).
I did spent few hours trying to understand the documentations, and quite a bunch of thread about it, but I did not find the basic answer of this basic question.
Is there a way to log these NameError, SytaxError, and any runtime error on a file.log?
Is there a command in the Python debugger (pdb) that says something like "run until the next exception is raised?"
Seems an obvious requirement but can't seem to find it.
Update : To be clear, my problem is an exception which is being caught and turned into an inadequate message in a log file. And I can't find where the exception is raised.
I figured that if I could go into trace mode and say "run until an exception is thrown" that would be the most straightforward way of finding it. I don't think post-mortem will work here.
Execute your script as follows:
python -m pdb myscript.py
Press c and Enter.
When an uncaught exception is raised you program will stop running and fall back to the pdb debug prompt.
Can you search the code in the failing script for the text of the message that is logged (I realize that this may be difficult if the string is generated in a complex way). If you can find the point where the message is generated/logged then you can set an appropriate break point to troubleshoot the problem.
Unfortunately, AFAIK Python pdb debugging does not offer the capability that is present in some other languages to say, for example, break when Exception is raised.
I have a script that has been crashing (seemingly) unpredictably. I can't work out how to reproduce it.
Does Python keep a global system log file, so I can go back and look at what exception precipitated the exit? If so, where can it be found on Windows? I'd like to be able to see a traceback too if possible.
edit: I know I could put the whole script inside a try...except block, but I don't know how long I'll be running it before it crashes again. I'd like to be able to at least gain some cursory information about crashes that have already happened, even if that information is just the type of exception that caused the crash. That way I can try to reproduce the bug more reliably.
I suspect the crash been caused by failed communication with external devices (perhaps something as simple a loose cable). These sorts of failure are essentially random and difficult to reproduce, so I'd like to know if it was a communication error or a genuine code bug.
If you want to know the information about exception you can use this code.
try:
#do some stuff
1/0 #stuff that generated the exception
except Exception as ex:
print ex
raw_input()
For debugging it properly there is a tool winpdb. There is a very good tutorial available for it to learn debugging using it debugging tutorial
Can you "catch" the exception? If yes, then you can use traceback to print the stacktrace and pinpoint where the problem occurs.
Then you can debug the module in question (even if it's part of the python lib, it will be in plain readable form) using Eclipse.
import traceback
...
...
try:
<your script>
except Exception as runtime_ex:
print runtime_ex, traceback.format_exc()