I have a thread which can print some text on the console and the main program have a raw_input to control the thread.
My problem is when I’m writing and the thread too I get something like this:
-->whatiwWHATTHETHREADWRITErite
but I would like to get some thing like this
WHATTHETHREADWRITE
-->whatiwrite
You have to syncronize your input with the thread output preventing them from happening at the same time.
You can modify the main loop like:
And then lock the background thread printing:
In short when you
Press Enteryou will stop the thread and enter in “input mode”.To be more specific, every time you
Press Enteryou will:-->and wait for your commandSo your thread will be stopped only if it tries to print when you are in “input mode”,
and in your terminal you’ll get something like: