74106

PyCharm Run — why does it sometimes display a traceback and error and sometimes not?

Question:

I've noticed that if I run the exact same piece of Python 3 code in PyCharm, the "Run" tab sometimes will show the full traceback and error message, but other times will only show "Process finished with exit code 1".

1) Can someone explain why this happens?

2) Is there some way to force PyCharm to always show the full traceback and error message?

Edit: Here is an example that shows the behavior that I've been seeing. When I ran this 20 times, I got the traceback and error twice and the "exit code 1" message by itself 18 times. In order to see this behavior, the code seems to need to be busy printing something before the exception is raised. If I only raise the exception (without the calling callme()) I always get the traceback and error.

#!/usr/bin/python3 def callme(): print('doing some stuff!') def main(): for i in range(1,100): callme() raise Exception('Something is went wrong!') if __name__ == '__main__': main()

Edit 2: I just realized that the answer to this probably has to be. The PyCharm Run display window only shows a certain number of lines. If the number of lines that it can print is less than the amount of stuff I am printing, then some of the lines won't show. So, actually the traceback lines are still there, but they just got printed way before some of the other output and so they aren't visible in the window. I found out that I can actually jump up to them (even if they aren't visible) by pressing the little up button next to the Run window.

Edit 3: Looks like I'm not the only person who has had this problem: <a href="https://stackoverflow.com/questions/28014357/pycharm-output-error-messages-interspersed-with-console-output-how-to-fix-this" rel="nofollow">PyCharm output error messages interspersed with console output. How to fix this?</a>

According to that question, it got reported as a bug (<a href="https://youtrack.jetbrains.com/issue/PY-16143" rel="nofollow">https://youtrack.jetbrains.com/issue/PY-16143</a>), but (as far as I can tell) it wasn't repaired. Any ideas on how to get around this?

For those who asked: I'm using PyCharm Community Edition 2016.3.2 and my operating system is CentOS 6.6.

Answer1:

I can confirm this behavior on Ubuntu 16.04 PyCharm 2017.2.3<br /> If you want to see stack trace every time, try this code and anyway <a href="https://www.loggly.com/blog/4-reasons-a-python-logging-library-is-much-better-than-putting-print-statements-everywhere/" rel="nofollow">stop using print for debugging</a> :)

import logging def callme(): logging.info('doing some stuff!') def main(): for i in range(1,100): callme() raise Exception('Something is went wrong!') if __name__ == '__main__': logging.basicConfig(level='INFO') main()

Recommend

  • Managing “this” in event/callback driven JavaScript applications
  • Lua function range
  • Group and sum items from two arrays
  • Special characters in property name
  • From an action, get a post variable, output to page, then halt execution
  • Django 1.8, syncdb not working, throwing a foreign key constraint error
  • Error handling only works once
  • Python validation mobile number
  • How to pass arrays into Scipy Interpolate RectBivariateSpline?
  • How to graph streaming data in C#
  • Tensorflow: “GraphDef cannot be larger than 2GB.” error when saving model after assigning variables
  • Capture reload/endrequest event after server redirect to download file
  • Ionic run android - Internal Error
  • Can I make OCaml produce stack traces on uncaught exceptions?
  • Read a file in “chunks” using PHP
  • How to synchronize two scrollview in Android?
  • iOS Localization Doesn't Work with More Than 63 Files
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Write output of for loop to multiple files
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Android Studio Can't Find tools.jar
  • Disable Kendo Autocomplete
  • Convert SQLite database to XML
  • SAVE attribute needed for Fortran variables when only the C_LOC address is returned to a C program?
  • Element.tagName for python not working
  • cygwin cannot exec 'git-add--interactive' permission denied
  • Odoo 10 - Overriding unlink method
  • Eclipse CDT error: Unable to compile
  • error importing numpy
  • Textfile Structure (tables)
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • QLineEdit password safety
  • javaw.exe and eclipse startup problems
  • Why winpcap requires both .lib and .dll to run?
  • align graphs with different xlab
  • Return words with double consecutive letters
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • need help with bizarre java.net.HttpURLConnection behavior
  • Reading document lines to the user (python)
  • Python/Django TangoWithDjango Models and Databases