, I only want to find a way to print message from other thread and
then cursor and ">" on the next line of the message
You need two threads, not just one, to illustrate the idea that you are trying to work on.
Let's consider this quick example. We have to create two threads, in this case we need to use a [Queue][1]
to pass data between threads. This answer can help explain why Queues should be preferred in a threaded environment.
In our example, you are going to update the queue in the first thread (put in the queue), and printing the message that you saved in the other thread (get it from the queue). If the queue is empty, we don't have to print any value.
This example can be a good starting point.
from threading import *
import time
import Queue # Queue in python2.x
def updateInput(messages):
text= "haha" #"This is just a test"
messages.put(text)
#anothertext= "haha" #"This is just a test"
#messages.put(anothertext)
def handleInput(messages):
try:
while True: # Optional, you can loop to, continuously, print the data in the queue
if not messages.empty():
text= messages.get()
print text
clientInput = raw_input("\r>")
except KeyboardInterrupt:
print "Done reading! Interrupted!"
if __name__ == "__main__":
messages = Queue.Queue()
writer = Thread(target=updateInput, args=(messages,))
worker = Thread(target=handleInput, args=(messages,))
writer.start()
worker.start()
writer.join()
worker.join()
This example should be a starting point, if you have any other question, let us know.