Threads are printing at the same time messing up the text output

Use a threading.Semaphore to ensure that there won’t be any conflicts:

screenlock = Semaphore(value=1)   # You'll need to add this to the import statement.

Then, before you call echo.message, insert this line in order to acquire the right to output:

screenlock.acquire()

and then this line after you call echo.message so as to allow another thread to print:

screenlock.release()

Leave a Comment