Skip to content

Instantly share code, notes, and snippets.

@cancan101
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cancan101/ac0dfde33a3909e459f8 to your computer and use it in GitHub Desktop.
Save cancan101/ac0dfde33a3909e459f8 to your computer and use it in GitHub Desktop.
#!/bin/sh
"exec" "python" "-u" "--" "$0" "$@"
import os
import sys
import time
class ForceIOStream:
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
if not self.stream.isatty():
os.fsync(self.stream.fileno())
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout = ForceIOStream(sys.stdout)
sys.stderr = ForceIOStream(sys.stderr)
for i in xrange(20):
print i
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment