I'm attempting to debug a Poetry script (that I didn't write) in PyCharm, but am running into problems with the Debug Configuration.
I am able to run the script without error directly from my bash shell. I used those parameters to set up my Run Configuration, which behaves as I expect. Here's the output from running without the debugger:
/Users/me/Library/Caches/pypoetry/virtualenvs/infra-KKsTCFNL-py3.9/bin/python /Users/me/Projects/infra/bin/my-script -c a_flag
Success!
So far so good; however, when I click debug, I get:
/Users/me/Library/Caches/pypoetry/virtualenvs/infra-KKsTCFNL-py3.9/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --client 127.0.0.1 --port 49371 --file /Users/me/Projects/infra/bin/my-script -c a_flag
Connected to pydev debugger (build 212.4746.96)
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader
key = self._selector.get_key(fd)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 193, in get_key
raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyError: '6 is not registered'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 523, in register
self._selector.control([kev], 0, 0)
TypeError: changelist must be an iterable of select.kevent objects
python-BaseException
Exception ignored in: <function BaseEventLoop.__del__ at 0x10e139820>
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
self.close()
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 63, in close
if self._signal_handlers:
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers'
sys:1: RuntimeWarning: coroutine 'main' was never awaited
Process finished with exit code 1
and here is the minimal my-script
#!/usr/bin/env python3
import asyncio
import sys
async def main():
print("Success!")
if __name__ == "__main__":
sys.exit(asyncio.run(main()))
So the error occurs before ever entering main(). I am somewhat at a loss for appropriate next steps -- is the problem Poetry? My Debug configuration? My interpreter?
Related
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.
I am using the python wrapper for Stanford openIE created by philipperemy at here:https://github.com/philipperemy/Stanford-OpenIE-Python. However, I am using a window system so I use Cygwin to run the following code:
git clone https://github.com/philipperemy/Stanford-OpenIE-Python.git
cd Stanford-OpenIE-Python
echo "Barack Obama was born in Hawaii." > samples.txt
python main.py -f samples.txt
However, I meet the error saying that
AssertionError: ERROR: Call to stanford_ie exited with a non-zero code status.
I am not sure how to fix it. I used a java version of 1.8.0_121 and I checked if I used the updated version of this Github file by using $ git pull origin master.
Does anyone knows how to fix this problem?
Thanks in advance!
To be more specific, the complete error message in here:
$ python main.py -f samples.txt
Namespace(filename='samples.txt', generate_graph=False, verbose=False)
Traceback (most recent call last):
File "main.py", line 147, in <module>
exit(main(argv))
File "main.py", line 142, in main
entities_relations = stanford_ie(filename, verbose, generate_graphviz)
File "main.py", line 118, in stanford_ie
assert not java_process.returncode, 'ERROR: Call to stanford_ie exited with a non-zero code status.'
AssertionError: ERROR: Call to stanford_ie exited with a non-zero code status.
The straight answer coming from the author of Stanford-OpenIE-Python is that Windows OS is not supported by the library. Details here
Interesting situation!
I has parser.py script, link to it below in 1, with feedparser library.
When i just started it, i get such exceptions:
Connected to pydev debugger (build 172.3757.67)
pydev debugger: process 20017 is connecting
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 354, in evaluate_expression
compiled = compile(expression, '<string>', 'eval')
File "<string>", line 1
feedparser.parse(http://www.malware-traffic-analysis.net/blog-entries.rss)
^
SyntaxError: invalid syntax
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1134, in do_it
result = pydevd_vars.evaluate_expression(self.thread_id, self.frame_id, self.expression, self.doExec)
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 356, in evaluate_expression
Exec(expression, updated_globals, frame.f_locals)
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<string>", line 1
feedparser.parse(http://www.malware-traffic-analysis.net/blog-entries.rss)
^
SyntaxError: invalid syntax
Even more, i didn't go to point with:
feedparser.parse(http://www.malware-traffic-analysis.net/blog-entries.rss)
Such problem appear over first import in script which import json!
Also in my code i get http strings from txt file, like:
RssProcess('rsslinks.txt')
So, first i thing that problem in this file and delete string
http[:]//www.malware-traffic-analysis.net/blog-entries.rss
from it. But it didn't help! So i has script that works perfectly, but it get exceptions which doesn't stop it. Exceptions i saw in PyCharm debugger.
My specs:
macOS Sierra 10.12.6
pycharm 2017.2
python 3.6.2
Link to GitHub
I have IIS setup with fastCGI, serving a flask app. So far so good. Next I whish to add some database connectivity, so I add the line import cx_Oracle to my app. Now this error is thrown:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "Bloomberg_server.app" could not be imported:
Traceback (most recent call last):
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File "D:\website\init__.py", line 6, in import cx_Oracle
ImportError: DLL load failed: The specified module could not be found. StdOut: StdErr:
As the title suggests I fail to reproduce the issue in a controlled environment. The very same import statement works fine in the conda environment and moreover, I can run the Flask debug server just fine with pages that rely on a database connection.
I am at loss. Who has a clue what's going on here? The path/oracle_home variables are pointing to the instant client and I have only one python environment installed.
I am too embarrased to admit how long this has taken me, but I've found the answer.
FastCGI's core business is keeping subprocesses alive so that subsequent calls to the server do not require booting a Python environment. In other words, after installing a python package it is advised to reboot. I solved my first question on SO by rebooting..
The answer to this question got me thinking in the right direction.
I get this error with multiprocessing when looping a simple range.
Process PoolWorker-37:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 249, in _bootstrap
sys.stdin.close()
AttributeError: StdIn instance has no attribute 'close'
The code
pool = multiprocessing.Pool(processes=3)
pool.map(get_info, range(20000,20010), 1)
pool.close()
pool.join()
Update
the first issue was by eclipse altering the environment, but now I get this error
PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed
This error is thrown if you are running in PyCharm console. I used the system console and all ran ok.
In PyCharm 4.5 the solution for me was to remove "Show command line afterwards" checkbox in server Run/Debug configuration for python file (which is not even documented in PyCharm manual)