0

I have known that with -u, the stdout buffer of python will be disabled. It works in sublime and bash, but in pycharm, I set Run->Edit Configurations->Interpreter options->add -u, it doesn't. My test code is as following:

# -*- encoding: utf-8 -*-
import sys
print "stdout1"
print >> sys.stderr, "stderr1"
print "stdout2"
print >> sys.stderr, "stderr2"
print "stdout3"
print >> sys.stderr, "stderr3"

Here is the result in "Run" window:

C:\Python27\python.exe -u "D:/Python Projects/compute - 2016.7.13/main.py"
stderr1
stderr2
stderr3
stdout1
stdout2
stdout3

Process finished with exit code 0

The results always change, it seems that '-u' doesn't work

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Ryan
  • 345
  • 3
  • 11

1 Answers1

1

I think the problem is not related to python buffered output: if you run your example in the console, the order would be correct. IDE handles output of the script process and has to catch both stdout and stderr, but it's not possible to preserve order when both streams are intercepted. Here are some relevant discussions: one, two, three.

Community
  • 1
  • 1
grundic
  • 4,641
  • 3
  • 31
  • 47