Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import threading
- class myclass(object):
- def __init__(self, oldstdout):
- self._global_write_lock = threading.Lock()
- self._output = oldstdout
- def __getattr__(self, attr):
- if attr == "write":
- return self.write
- return getattr(self._output, attr)
- def write(self, *args):
- self._global_write_lock.acquire()
- self._output.write(*args)
- self._global_write_lock.release()
- sys.stdout = myclass(sys.stdout)
- print "Hello, world!"
Add Comment
Please, Sign In to add comment