Guest User

Untitled

a guest
Jun 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import sys
  2. import threading
  3.  
  4. class myclass(object):
  5. def __init__(self, oldstdout):
  6. self._global_write_lock = threading.Lock()
  7. self._output = oldstdout
  8.  
  9. def __getattr__(self, attr):
  10. if attr == "write":
  11. return self.write
  12.  
  13. return getattr(self._output, attr)
  14.  
  15. def write(self, *args):
  16. self._global_write_lock.acquire()
  17. self._output.write(*args)
  18. self._global_write_lock.release()
  19.  
  20. sys.stdout = myclass(sys.stdout)
  21.  
  22. print "Hello, world!"
Add Comment
Please, Sign In to add comment