I am writing a script which has 5 threads, i want to share/redirect stdout for all the thread, to get all prints properly. I have tried with the below code but its not working, can anybody help?
class Logwriter():
def __init__(self):
self.terminal = sys.stdout
def write(self,message):
lock = threading.Lock()
lock.acquire()
self.terminal.write(message)
lock.release()
sys.stdout=Logwriter()