Is python\'s print synchronized? :)
Between Threads.
Kind of workaround... It does not print synchronized, but it is monolithic and thus the threads will not write on top of each other.
Pros: Does not require locking and thus is faster.
Cons:
import threading, time
class SomeThread(threading.Thread):
def __init__(self, name):
super().__init__()
self.name = name
...
def mono_print(self, *v):
p = time.strftime("%Y-%m-%d %H:%M:%S") + ' ' + self.name
for s in v:
p += ' ' + str(s)
print(p + '\n', end='', flush=True)
def run(self):
self.mono_print('thread is running.')
...
self.mono_print('something', 'them something else')
...
self.mono_print('processed')