PyCharm 2019.2 not showing Traceback on Exception - python

Very simple minimal example:
if __name__ == '__main__':
print("Still ok")
raise Exception("Dummy exception")
print("End of Program")
I get this output when running it in the PyCharm 2019.2 debugger with Python 3.6:
/usr/bin/python3.6 /home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 46850 --file /home/[...]/test_traceback.py
pydev debugger: process 18394 is connecting
Connected to pydev debugger (build 192.5728.105)
Still ok
At this point the debugger breaks the execution flow but no Traceback and Exception message is shown in the Debugger console. If I run the same in PyCharm 2018.1 it does show these right when the breakpoint is hit.
When I hit , I get the desired output, but then I can't run code in the debugging context anymore because the process ends:
Traceback (most recent call last):
File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 2060, in <module>
main()
File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 2054, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 1405, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "/home/[...]/pycharm-community-2019.2/helpers/pydev/pydevd.py", line 1412, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/[...]/pycharm-community-2019.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/[...]/test_traceback.py", line 4, in <module>
raise Exception("Dummy exception")
Exception: Dummy exception
Process finished with exit code 1
My Breakpoint configuration:

It works on PyCharm (Community) 2019.1.4:
Seems like you ran into a (regression) bug:
[JetBrains.YouTrack]: No Traceback in Debugger's Console
[JetBrains.YouTrack]: No stack trace is printed to the console when debugger breaks on exception
which affects v2019.2.1, and is scheduled to be fixed in v2019.2.3.
To get past this issue, you'll have to either:
Wait for v2019.2.3 (or any other that has the fix) to be released, and switch to that (might want to (periodically) check [JetBrains.Blog]: Release Announcements)
Revert to a (previous) version which is not affected by the bug (as I already mentioned: 2019.1.4)
As a note: when running into this kinds of situations, in the (unlikely) case that the problem is not yet known, one could take matters into their own hands, do some debugging, and fix the problem (maybe submit a patch with the fix to JetBrains). Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? for an example.
Update #0
Installed (on 20190930) latest patch (v2019.2.3), and the traceback is present in PyCharm's console (so, the bug is fixed).

did you check your whitespaces at start of each executable line? one time it occured to me was fixed after just correcting the whitespaces.

Related

Why does PyCharm try to reacquire stdin upon termination?

MCVE:
import threading
threading.Thread(target=input, daemon=True).start()
If you run the above as a script in PyCharm with the default run configuration (without entering any input), you get the following fatal error when the program terminates:
Fatal Python error: could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=00000200EF89E1C0)
Thread 0x0000459c (most recent call first):
File "C:\Program Files\Python38\lib\threading.py", line 870 in run
File "C:\Program Files\Python38\lib\threading.py", line 932 in _bootstrap_inner
File "C:\Program Files\Python38\lib\threading.py", line 890 in _bootstrap
Current thread 0x00001b78 (most recent call first):
<no Python frame>
But if you run this from the terminal with python script.py or check the "Emulate terminal in output console" in PyCharm for this run configuration, no such error occurs.
As far as I understand, the error happens because when input is called, it suspends the thread indeterminately until input returns (and there's no way of interrupting this), blocking stdin during this time, so when the main thread terminates, since the other thread is a daemon, Python starts finalization, and when it tries to reacquire the lock for stdin, it can't because it is still locked by the input call.
But the question is, why does it make a difference whether it is run in PyCharm's output console vs a terminal/terminal emulator? Does the terminal make Python not try to reacquire the lock? Or does the error still occur but it gets silenced for some reason? Or what?
If case this helps, in CPython, this error is raised in the _enter_buffered_busy function in bufferedio.c.
UPDATE: I've filed a ticket on PyCharm's issue tracker.

How do I debug with PyCharm while using Vagrant

I am new to Python. I am new to Vagrant. However, my team runs their project using a Vagrant VM and IDEs of their own choosing. I chose PyCharm, because I've used some JetBrains products in the past.
I'd really like to be able to visually debug through it as it is running. Set a break point, view the values of variables, etc.
PyCharm has a help section (and the related articles above it):
https://www.jetbrains.com/help/pycharm/configuring-product-to-work-on-the-vm.html
I've done all of them, but under Project->Project Interpreter the Path Mappings seem to list all the shared folders on the between the host machine and the Vagrant VM. Those shared folders are
one directory up from the actual project
my vagrant directory
My home directory
I don't think it is pointing to the project or its dependency libraries correctly.
I also get a yellow message at the bottom that says Python packaging tools not found.
If I hit debug, I get the following output in a terminal:
bash: line 0: cd: /vagrant/app: No such file or directory
pydev debugger: process 2032 is connecting
Connected to pydev debugger (build 191.6183.50)
Traceback (most recent call last):
File "/home/vagrant/.pycharm_helpers/pydev/pydevd.py", line 1741, in
<module>
main()
File "/home/vagrant/.pycharm_helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/vagrant/.pycharm_helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
IOError: [Errno 2] No such file or directory: '/vagrant/app/__main__.py'
It also has opened itself a tab for 'pydev.py' that has in it:
Remote file /home/vagrant/.pycharm_helpers/pydev/pydevd.py is mapped to the
local path C:\Users\<my username>\vagrant\.pycharm_helpers\pydev\pydevd.py
and can't be found. You can continue debugging, but without the source. To
fix that you can do one of the following:
How can setup to debug from PyCharm on my host machine through code running on the Vagrant VM?

pydev debugger not working but can run code fine

I am using Liclipse which is basically pydev with eclipse. The python file runs fine but when I try to use the pydev debugger on the same file the debugger fails to launch and I couldn't find anything about this error. Is it a bug in pydev? It even says "During handling of the above exception, another exception occurred"
I am using python 3.7.1
warning: Debugger speedups using cython not found. Run '"C:\Users\q4116\AppData\Local\Programs\Python\Python37-32\python.exe" "C:\Program Files\Brainwy\LiClipse 5.1.0\plugins\org.python.pydev.core_7.0.0.201811071259\pysrc\setup_cython.py" build_ext --inplace' to build.
pydev debugger: starting (pid: 20104)
Traceback (most recent call last):
File "_pydevd_bundle\pydevd_cython_win32_37_32.pyx", line 134, in _pydevd_bundle.pydevd_cython_win32_37_32.set_additional_thread_info
AttributeError: '_MainThread' object has no attribute 'additional_info'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Brainwy\LiClipse 5.1.0\plugins\org.python.pydev.core_7.0.0.201811071259\pysrc\pydevd.py", line 1951, in <module>
main()
File "C:\Program Files\Brainwy\LiClipse 5.1.0\plugins\org.python.pydev.core_7.0.0.201811071259\pysrc\pydevd.py", line 1945, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\Brainwy\LiClipse 5.1.0\plugins\org.python.pydev.core_7.0.0.201811071259\pysrc\pydevd.py", line 1295, in run
self.notify_thread_created(thread_id, t)
File "C:\Program Files\Brainwy\LiClipse 5.1.0\plugins\org.python.pydev.core_7.0.0.201811071259\pysrc\pydevd.py", line 662, in notify_thread_created
additional_info = set_additional_thread_info(thread)
File "_pydevd_bundle\pydevd_cython_win32_37_32.pyx", line 138, in _pydevd_bundle.pydevd_cython_win32_37_32.set_additional_thread_info
File "_pydevd_bundle\pydevd_cython_win32_37_32.pyx", line 147, in _pydevd_bundle.pydevd_cython_win32_37_32.set_additional_thread_info
File "_pydevd_bundle\pydevd_cython_win32_37_32.pyx", line 95, in _pydevd_bundle.pydevd_cython_win32_37_32.PyDBAdditionalThreadInfo.__init__
AttributeError: '_pydevd_bundle.pydevd_cython_win32_37_32.PyDBAdditionalThreadInfo' object has no attribute 'pydev_state'
Sorry about that. This is a bug in PyDev 7.0.0. I just finished uploading a new version for PyDev and LiClipse is almost there too (limiting factor is my internet connection speed, so, should be available in a few hours).
Meanwhile, removing the accelerators (and recreating if you want locally) should make it work again. i.e.: Remove _pydevd_bundle*.pyd and _pydevd_bundle\pydevd_frame_eval*.pyd and execute setup_cython.py locally (or don't if you're ok on going without the accelerator modules).
I had the same issue after an update of these packages :
Oomph Setup 1.11.0.v20181107-0652 org.eclipse.oomph.setup.feature.group Eclipse Oomph Project
PyDev for Eclipse 7.0.0.201811071319 org.python.pydev.feature.feature.group Fabio Zadrozny
PyDev for Eclipse Developer Resources 7.0.0.201811071319 org.python.pydev.feature.source.feature.group Fabio Zadrozny
Not running LiClipse but just Eclipse + pydev.
I solved it for now by reverting the update. Click Help > About Eclipse IDE > Installation Details > Installation History > Click on the last working version > Revert
I should have kept the error information though so that I could file a proper bug report ...

Spyder Ipython console completely ignores print statements

After I did some upgrade, I noticed If I'm printing in a script or even in the console, nothing is shown. I even remember in a previous version (I did a lot of upgrades recently) there was a tab right next to Ipython where the print output was showing, but after upgrading Spyder, it's gone. I've also been getting a lot of kernel died, restarting, and it's been really close to unusable. I used to love spyder, now I waste too much time closing/restarting/resetting just to get my work done.
I'm using Anaconda 3.5.
And just while I was writing this post, a tab called "Internal console" just popped up from nowhere and tells me the following:
Spyder Internal Console
This console is used to report application
internal errors and to inspect Spyder
internals with the following commands:
spy.app, spy.window, dir(spy)
Please don't use it to run your code
>>> WARNING:root:kernel died: 6.001342296600342
WARNING:root:kernel died: 6.000344276428223
Traceback (most recent call last):
File "C:\Users\Ahmad\Anaconda3\lib\site-packages\qtconsole\console_widget.py", line 412, in eventFilter
return self._event_filter_console_keypress(event)
File "C:\Users\Ahmad\Anaconda3\lib\site-packages\qtconsole\frontend_widget.py", line 381, in _event_filter_console_keypress
return super(FrontendWidget, self)._event_filter_console_keypress(event)
File "C:\Users\Ahmad\Anaconda3\lib\site-packages\qtconsole\console_widget.py", line 1130, in _event_filter_console_keypress
self.copy()
File "C:\Users\Ahmad\Anaconda3\lib\site-packages\qtconsole\frontend_widget.py", line 249, in copy
was_newline = text[-1] == '\n'
IndexError: string index out of range
Spyder lets you configure your run options. You can run in an external console or in your current python or ipython console. Maybe the default changed when you upgraded?
http://www.southampton.ac.uk/~fangohr/blog/spyder-the-python-ide.html#run-settings

python and TCL: how to run scripts that need a console

I am trying to run TCL scripts from Python. I have a third-party TCL package included in the TCL script (which I have to use) which makes calls to "console". Because of this, if I just run the following:
z = x.tk.eval('source C:/somePath/GetStatsFirst2.tcl')
I get the following error:
pydev debugger: starting
WARNING!!! Unable to add paths from Appinfo: Could not find AppInfo registry entry
WARNING!!! Unable to add paths from Appinfo: Could not find AppInfo registry entry
Traceback (most recent call last):
File "C:\Users\lab\Documents\Public\eclipse\plugins\org.python.pydev_2.7.5.2013052819\pysrc\pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "C:\Users\lab\Documents\Public\eclipse\plugins\org.python.pydev_2.7.5.2013052819\pysrc\pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "C:\Users\lab\Documents\Public\workspace\Version 1\....\TC1.py", line 55, in <module>
test()
File "C:\Users\lab\Documents\Public\workspace\Version 1\....\TC1.py", line 42, in test
z = x.tk.eval('source C:/Users/lab/Documents/Public/TCL/Scripts/GetStatsFirst2.tcl')
_tkinter.TclError: invalid command name "console"
This definitely has something to do with the package I am using and the problem may be unavoidable. Since there is no TK console that is opened (because I am using the TK inter class and eval), I get the feeling there is a way around this. It looks to me like the package I am importing requires the existence of a TK console. When run on the command line, or through subprocess.call, everything works, but in those cases a console is opened. I am pretty sure the package is actually looking for a console. Is there a way to create the console along with the Tk object?
Ahh, the console command.
The console command is only available
on Windows
only with wish
and only in the master interp.
I suggest that you use tkcon instead. You just need to find the tkcon.tcl file, source it before you source GetStatsFirst2.tcl and execute the following Tcl command:
interp alias {} console {} tkcon
This uses tkcon as console then.
Edit: You can execute that Tcl command with
x.tk.eval('interp alias {} console {} tkcon')
in Python.

Categories