Aquí les dejo una foto de los 2 errores que me da el script:
http://imgur.com/a/OPhpF
Intenté solucionar lo anterior buscando a ver como se podía hacer que MySQL trabajara con distintos puertos, para asignarle a cada hilo un puerto pero no he conseguido nada.
De todas formas aquí les dejo el código, solo vean el contexto de como aplico el procesamiento multi-hilo, si pueden entenderlo, mejor, así me dicen en qué me equivoco. Por cierto, he verificado que todo está bien: los nombres de los campos y tablas coinciden correctamente, así que por ese lado no ocurre algún error.
Antiguamente cuando no utilizaba el multi-hilos (que tenía el código con menos funciones) todo iba a la perfección, los problemas llegaron con eso y supongo que estoy haciendo varias cosas mal de las que no me doy cuenta. Aquí se los dejo:
Código
# -*- coding: utf-8 -*- import threading import mysql.connector import win32con import sys, os import struct import time from win32api import * from win32gui import * from mysql.connector import Error from threading import Thread cnx = mysql.connector.connect(host="localhost", user="root", password="1234", database="gammu") cnx2 = mysql.connector.connect(host="localhost", user="root", password="1234", database="gammu") cnx3 = mysql.connector.connect(host="localhost", user="root", password="1234", database="gammu") cursor = cnx.cursor() cursor2 = cnx.cursor() cursor3 = cnx.cursor() global errKey global errHash class WindowsBalloonTip: def __init__(self, title, msg): message_map= { win32con.WM_DESTROY: self.OnDestroy, } wc = WNDCLASS() hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = "NotificationTaskR" wc.lpfnWndProc = message_map classAtom = RegisterClass(wc) style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = CreateWindow(classAtom, "Taskbar", style, 0, 0, \ wind32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) UpdateWindw(self.hwnd) iconPathName = os.path.abspath(os.path.join(sys.path[0], 'balloontip.ico')) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE try: hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0,0, icon_flags) except: hicon = LoadIcon(0, win32con.IDI_APPLICATION) flags = NIF_ICON | NIF_MESSAGE | NIF_TIP nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "New message received") Shell_NotifyIcon(NIM_ADD, nid) Shell_NotifyIcon(NIM_MODIFY, (self.hwnd, 0, NIF_INFO, win32con.WIM_USER+20, \ hicon, "Balloon tooltip", msg, 200, title)) time.sleep(3) DestroyWindow(self.hwnd) classAtom = UnregisterClass(classAtom, hinst) def OnDestroy(self, hwnd, msg, wparam, lparam): nid = (self.hwnd, 0) Shell_NotifyIcon(NIM_DELETE, nid) PostQuitMessage(0) def balloon_tip(title, msg): w = WindowsBalloonTip(title, msg) def newWh(): while True: cnx.connect() lastRquery = ("select UpdatedInDB, AES_DECRYPT(TextDecoded, (select AES_DECRYPT(cryptkey, '373630303a3a3') from decryptkey)), " "AES_DECRYPT(SenderNumber, (select AES_DECRYPT(cryptkey, '373630303a3a3') from decryptkey)), ID from inboxencrypt where " "chck=0 order by UpdatedInDB asc limit 1") cursor.execute(lastRquery) regL = cursor.fetchall() if not regL: cnx.close() import time time.sleep(3) continue else: for row in regL: time = row[0] timeC = str(time) timeO = timeC[10:] message = row[1] telephone = row[2] toUR = row[3] lengM = len(message) smsDetect = message[27:] procMR = message.split() if procMR[0] == "\send": #Detect first command cnx.close() cnx.connect() queryAuth = ("SELECT privkey FROM transferauth WHERE " "privkey=sha(%s)", procMR[1]) cursor.execute(queryAuth) authStorage = cursor.fetchall() for row in authStorage: key = authStorage[0] if procMR[1] == key: #Detect authentication key if procMR[2] == "\a": #Detect command to send multiple messages to all contact list print("Ok") elif len(procMR[2]) == 13: #Send message to specific contact if telpComm[0] == "+" and telpComm [1:3] == "58": #Verifying international code telpComm == procMR[2] if len(smsDetect) > 3: #Verifying minimum message length if smsDetect[-1] == '"' and smsDetect[0] == '"': #Verifying message format and sending message msgToSend = smsDetetct[1:-1] cnx.close() cnx.connect() sendQuerExt = ("insert into outbox(DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','PwC')" % (telpComm, msgToSend)) cursor.execute(sendQuerExt) cnx.commit() cnx.close() #Reconnecting to database and ipdating message status cnx.connect() updateRquery = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep(3) print("~~~Send message is required for: "+telephone) print("~~~Send message in required for: "+telpComm+"\n\n") continue else: #Invalid message format => ERR_FORMATSMS_INVALID cnx.connect() srcErrorSource = ("select errordesc, hexcode from transfererrors " "where cause='ERR_FORMATSMS_INVALID'") cursor.execute(srcErrorSource) errStorageA = cursor.fetchall() for row in errStorageA: errKey = row[0] errHash = row[1] cnx.close() cnx.connect() recQueryErrorNumb = ("insert into outbox(Text, DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','%s','PwC')" % (errHash, telephone, errKey)) cursor.execute(recQueryErrorNumb) cnx.commit() cnx.close() #Reconnecting to database and updating message status cnx.connect() updateRquery = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep(3) continue else: #Minimum message length required => ERR_LENGTHSMS_INVALID srcErrorSource = ("select errordesc, hexcode from transferrors " "where cause='ERR_LENGTH_INVALID'") cursor.execute(srcErrorSource) errStorageA = cursor.fetchall() for row in errStorageA: errKey = row[0] errHash = row[1] cnx.close() cnx.connect() recQueryErrorNumb = ("insert into outbox(Text, DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','%s','PwC')" % (errHash, telephone, errKey)) cursor.execute(recQueryErrorNumb) cnx.commit() cnx.close() #Reconnecting to database and updating message status cnx.connect() updateRquery = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep(3) continue else: #Wrong international telephone format => ERR_FORMATNUMBER_INVALID srcErrorSource = ("select errordesc, hexcode from transfererrors " "where cause='ERR_FORMATNUMBER_INVALID'") cursor.execute(srcErrorSource) errStorageA = cursor.fetchall() for row in errStorageA: errKey = row[0] errHash = row[1] cnx.connect() recQueryErrorNumb = ("insert into outbox(Text, DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','%s','PwC')" % (errHash, telephone, errKey)) cursor.execute(recQueryErrorNumb) cnx.commit() cnx.close() #Reconnecting to database and updating message status cnx.connect() updateRquery = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep(3) continue else: #Unknown message or command => ERR_TLPNUMBER_INVALID srcErrorSource = ("select errordesc, hexcode from transfererrors " "where cause='ERR_TLPNUMBER_INVALID'") cursor.execute(srcErrorSource) errStorageA = cursor.fetchall() for row in errStorageA: errKey = row[0] errHash = row[1] cnx.close() cnx.connect() recQueryErrorNumb = ("insert into outbox(Text, DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','%s','PwC')" % (errHash, telephone, errKey)) cursor.execute(recQueryErrorNumb) cnx.commit() cnx.close() #Reconnecting to database and updating message status cnx.connect() updateRquery = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep() continue else: #Authetication error, wron key => ERR_AUTHKEY_INVALID srcErrorSource = ("select errordesc, hexcode from transfererrors " "where cause='ERR_AUTHKEY_INVALID'") cursor.execute(srcErrorSource) errStorageA = cursor.fetchall() for row in errStorageA: errKey = row[0] errHash = row[1] cnx.close() cnx.connect() recQueryErrorNumb = ("insert into outbox(Text, DestinationNumber, " "TextDecoded, CreatorID) values " "('%s','%s','%s','PwC')" % (errHash, telephone, errKey)) cursor.execute(recQueryErrorNumb) cnx.commit() cnx.close() #Reconnecting to database and updating message status cnx.connect() recQueryErrorNumb = ("update inbox set chck=1 where " "ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() #Wait for re-establish loop import time time.sleep() continue else: print("|| "+telephone+"\t\t"+timeO) print("|| "+message+"\n\n") balloon_tip("Mensaje recibido",message+"\nDe: "+telephone+"\t"+timeO) file = open("smscenter.log","a") file.write("Message was received at: "+timeO+"\n") file.write("----------------------------------------\n") file.write("|| "+telephone+"\n") file.write("|| "+message.encode("utf8")+"\n") file.write("-----Length of sms: "+str(lengM)+"\n") file.write("-----Recognize: \n\n\n") file.close() cnx.close() cnx.connect() updateRquery = ("update inbox set chck=1 where ID=%s" % toUR) cursor.execute(updateRquery) cnx.commit() cnx.close() import time time.sleep(3) continue def readWh(): while True: cnx2.connect() lastRquery2 = ("select UpdatedInDB, TextDecoded, SenderNumber, ID from inbox where " "chck=0 order by UpdatedInDB asc limit 1") cursor2.execute(lastRquery2) regL2 = cursor2.fetchall() if not regL2: cnx2.close() cnx2.connect() queryTrunc = ("delete from inbox where chck=1") cursor2.execute(queryTrunc) cnx2.commit() cnx2.close() import time time.sleep(3) continue else: for row in regL2: timeReceived = row[0] timeReceivedC = str(timeReceived) timeReceivedO = timeReceivedC[10:] messageRec = row[1] telephoneRec = row[2] idRec = row[3] cnx2.close() print("Hola menor") cnx2.connect() queryA = ("insert into inboxencrypt(id, UpdatedInDB, TextDecoded, SenderNumber) " "values (%s, %s, AES_ENCRYPT('%s', (select AES_DECRYPT(cryptkey, '373630303a3a3') from decrypkey)), " "AES_ENCRYPT('%s', (select AES_DECRYPT(cryptkey, '373630303a3a3') from decrypkey)))") cursor2.execute(queryA) cnx2.commit() cnx2.close() #Drop message cnx2.connect() queryB = ("update inbox set chck=1 where " "ID=%s" % idRec) cursor2.execute(queryB) cnx2.commit() cnx2.close() cnx2.connect() queryC = ("delete from inbox where chck=1") cursor2.execute(queryC) cnx2.commit() cnx2.close() continue def sentWh(): while True: cnx3.connect() lastRquery3 = ("select UpdatedInDB, InsertIntoDB, SendingDateTime, DestinationNumber, " "TextDecoded, ID, Status, CreatorID from sentitems where chck=0 order by UpdatedInDB asc limit 1") cursor3.execute(lastRquery3) regL3= cursor3.fetchall() if not regLr: cnx3.close() cnx3.connect() queryTrunc1 = ("delete from sentitems where chck=1") cursor3.execute(queryTrunc1) cnx3.commit() cnx3.close() import time time.sleep(3) print("Hola menor") continue else: for row in regL3: timeUpdated = row[0] timeInsert = row[1] timeSent = row[2] telephoneSent = row[3] messageSent = row[4] idSent = row[5] status = row[6] creator = row[7] cnx3.close() cnx3.connect() print("Hola menor") queryD = ("insert into sentencrypt(id, UpdatedInDB, InsertIntoDB, SendingDateTime, " "DestinationNumber, TextDecoded, Status, CreatorID) values " "(%s, '%s', '%s', '%s', " "AES_ENCRYPT('%s', (select AES_DECRYPT(cryptkey, '373630303a3a3') from decrypkey)), " "AES_ENCRYPT('%s', (select AES_DECRYPT(cryptkey, '373630303a3a3') from decrypkey)), " "'%s', AES_ENCRYPT('%s', (select AES_DECRYPT(cryptkey, '373630303a3a3') from decrypkey)))" % (idSent, timeUpdated, timeInsert, timeSent, telephoneSent, messageSent, status, creator)) cursor3.execute(queryD) cnx3.commit() cnx3.close() #Drop message cnx3.connect() queryZ = ("update sentitems set chck=1 where " "ID=%s" % idSent) cursor3.execute(queryZ) cnx3.commit() cnx3.close() cnx3.connect() queryE = ("delete from sentitems where chck=1") cursor.execute(queryE) cnx3.commit() cnx3.close() import time time.sleep(3) continue if __name__ == '__main__': print("Be sure you have Windows pop-ups notifications enabled.\n\n") print("SMS Center will show pop-ups notifications when message is being received." "\nThis window need to be open at anytime.") Thread(target = newWh).start() Thread(target = readWh).start() Thread(target = sentWh).start()