-2
I have a Thread from a function that inserts data into the database and another Thread that every second receives a new value for a variable, however it may be the same previous value only "new". I wanted to know how I make the thread expect this new value and every time I receive this new value do the Insert in the bank. A part of my code :
def EnviaBanco():
    global nomepessoa  # nomepessoa é uma variavel global em outra função, esse nomepessoa esta  dentro de um  while que  esta recebendo um novo valor  a  todo momento
    global cam
    Conectando banco de dados
    try:
        mydb = mysql.connector.connect(
          host="localhost",
          user="teste",
          password="teste102030",
          database="teste"
        )
        print ("Conexão realizada com sucesso")
    except:
        print("[ERROR] verifique a conexão com banco  de dados")
    
    while True:
    " if nomeatual recebeu um novo valor: "
        time.sleep(10.0)
        #Inicializando banco
        mycursor = mydb.cursor()
        #Inserindo dados
        sql = ("INSERT INTO teste (nomes, camera) VALUES (%s,%s)")
        #Executando os dados  e comitando
        mycursor.execute(sql,(nomepessoa, cam))
        mydb.commit()
        print("Dados inseridos com sucesso")
'''
The logic of your function is a little strange. Creating a cursor inside the loop is not a good practice. Avoid using
global. I will answer below in a generic way, because I do not know how you take the data.– Paulo Marques
1) Why have a thread just for insertion? 2) If really necessary, read about the queue data structure (Queue).
– Woss