Exception in thread pydevd.CommandThread (most likely raised during interpreter shutdown) - PyDev - python

I've made a single-threaded Python program in PyDev, and after the program executes and reports that it's done, I get the following error message:
Exception in thread pydevd.CommandThread (most likely raised during interpreter shutdown):
It doesn't affect how my program runs, but it would be nice to have it not show up. I've run the program on the command line, and it doesn't produce any error messages like this.
Any suggestions?

Apparently it was the way I was writing to a file using the built-in json library.
I don't know why or if it was wrong, but I stopped the error by using
file.write(json.dumps(dict, indent=4))
instead of
json.dump(dict, file, indent=4)
I'm not sure why this was producing the error, but changing this made it stop. If anyone can let me know why, that would be great.

Related

PyCares - Fatal Python error: PyImport_GetModuleDict: no module dictionary

I've been trying to get a script to run on a Windows server. It runs fine on my Mac, but keeps throwing an error at the end of the script. The output from the script is as expected and completes entirely, then this error is thrown:
Fatal Python error: PyImport_GetModuleDict: no module dictionary
Current thread 0x00001880 (most recent call first):
File "C:\Python37\lib\site-packages\pycares\__init__.py", line 387 in (lambda)
Currently I'm running Python 3.6.5 and getting this error but I've tried it up to Python 3.7.5 and get the same error. This seems like a Windows specific issue with Pycares since the same script runs fine on my Mac machine. Since the script executes correctly, even on windows, this seems like it is an error thrown in the cleanup of the script.
Any ideas on a cause or a workaround?
Edit: I've found this Python bug https://bugs.python.org/issue26153 that seems to say it's due to a race condition and warnings in the del function, but I still get the issue even when running Python 3.7

Windows console prompt doesn't show up after an unhandled exception

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.
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.
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.

Python Job Not Ending

I've had a strange occurance. I stopped a python script manually, but its still running. It shows it as stopped in my IDE (Spyder) but I can see it's still running in task manager. I also know it still processing because its still outputting files to a directory.
Does anyone know why this is happening and how I can prevent it on a go forward?
Got it, i needed to add Exception to my except statement. Thanks gerosalesc and Dot_Py for your help.
Try/Except in Python: How do you properly ignore Exceptions?

Where should I start to debug a python program with "Segmentation fault: 11"

I have a python script test.py.
Running python test.py gives the brief message:
Segmentation fault: 11
In general, where should I start to debug such an issue?
In general (and without specifics for your code), the best thing to do is start putting print statements into your test script until you can narrow things down to a single line that is causing the segfault. Put in a bunch of print statements and move them around as you start narrowing down which print statements run and which ones don't because they are after the segfault.
If your Python script is causing a segmentation fault, that usually means that some Python module that is implemented in C is doing something wrong. You should be able to tell easily using gdb. Try running:
gdb `which python`
# This starts an interactive gdb session. Type:
set args /path/to/python/script.py
r
# The program will now run. Interact with it until the segfault occurs. Then type:
bt
This will give you the c call stack leading up to the segmentation fault. (gdb may print a message about missing debug symbols, and give you the command to run to install them. Debug symbols will give you a more detailed stack trace, including function names and line numbers of files.) Use this information to more quickly determine what call in Python is causing the segfault.

Is there any linux tool can find the process trace of a python program?

I have a python process running now , but it hangs with no log、no exception, i don't know what's going on with it.
This bug turns out every 5 or 6 hours, so this time i don't want to kill the process and trying to find a way to trace which line it hangs.
I have tried PStack , but i can't understand the system call it lists.
Is there any tool can show me which line the program hangs, it will be perfect if the trace info shows in python ?
You can use gdb with python: http://docs.python.org/devguide/gdb.html which can give you a traceback of the python stack.

Categories