Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

python - Enthought Canopy doesn't print right away when statement occurs

A while ago I switched from Enthought's old EPD to their newer Canopy system. For the most part it's nice, but one aspect has been particularly vexing.

Whenever I run a python script, either from within the Canopy iPython environment or from the command line, none of my print statements actually get printed right away when that part of the script is hit. Instead, multiple prints seem to get executed all at once at a later time.

As an example...

import numpy as np

print "About to start long computation..."
a = np.random.randn(1e8)
print "Computation finished."

doesn't print the first statement until after a is finished being generated, when both statements are printed simultaneously. (You can tell when the calculation is occurring by watching the CPU monitor.)

Does anyone know what's going on here? If relevant, I'm running Canopy 1.0.0.1160, with Python 2.7.3 64bit on a Windows 7 machine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This looks like buffered output. Try running your script as:

python -u yourscript

The -u flag turns buffering off.

(Replace python by your OS's python executable's name.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...