Created
July 29, 2012 19:41
-
-
Save rtomaszewski/3201382 to your computer and use it in GitHub Desktop.
Primitive logging functions in your python scripts that are buffered before will be printed on the stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Try to execute the script in two different modes to see the difference | |
# | |
# $ python log.py | tee log | |
# <noting for a long time> | |
# | |
# $ python -u log.py | tee log | |
# my log message 0 | |
# | |
import time | |
DEBUG = 0 | |
def log(message): | |
print message | |
def debug(message): | |
if DEBUG>0: | |
log("debug[%2d]: " % DEBUG + message) | |
if __name__ == '__main__': | |
for i in range(0,1000): | |
log("my log message " + str(i)) | |
time.sleep(1) | |
debug("my debug message" + str(i)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Written for this blog entry:
My python script buffers the output and it causes delays before the text appiers on the console
http://rtomaszewski.blogspot.co.uk/2012/07/my-python-script-buffers-output-and-it.html