0

I have a thread that verifies results of my database and raw_input to input more data. The problem is that the thread is printed on the raw_input. Something like that.

input> DATAOFTHREAD

but I want to print the result something like that

DATAOFTHREAD
input>

...

def handler(de_user,idChat):
    db = MySQLdb.connect('localhost','user','passwd','database')
    cursor = db.cursor()
    oldata = 0
    write = sys.stdout.write
    while True:
        db.commit()
        cursor.execute("SELECT id FROM mensajes WHERE De_user='%s' AND idChat='%s' ORDER BY id DESC LIMIT 0,1"%(de_user,idChat))
        traer_id = cursor.fetchall()
        if traer_id:
            for j in traer_id:
                data = j[0]
        if oldata != 0:
            if oldata != data:
                cursor.execute("SELECT Mensaje FROM mensajes WHERE De_user='%s' AND id>'%d'"%(de_user,oldata))
                traer_mensajes = cursor.fetchall()
                if traer_mensajes:
                    for i in traer_mensajes:
                        Mensaje = i[0]
                        Mensaje = base64.decodestring(Mensaje)
                        write(de_user+' > '+Mensaje)
                        write('\n')
                    oldata = data
        else:
            oldata = data

t = Thread(target=handler, args=(de_user, idChat))
t.daemon = True
t.start()
while True:
    contestar = raw_input('> ')
    print "\033[A                                        \033[A"
    #Validations

SOLVED: Reading input from raw_input() without having the prompt overwritten by other threads in Python

thanks to those who helped me

Community
  • 1
  • 1
user3720124
  • 33
  • 1
  • 7

0 Answers0