Advertisement
Guest User

Untitled

a guest
May 4th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import mysql.connector
  2. import threading
  3. import time
  4.  
  5. def updateA(conn, data, idd):
  6. cursor = conn.cursor()
  7. cursor.execute ("UPDATE A SET data=%s WHERE id=%s", (data, idd))
  8. conn.commit()
  9.  
  10. def updateB(conn, data, idd):
  11. cursor = conn.cursor()
  12. cursor.execute ("UPDATE B SET data=%s WHERE id=%s", (data, idd))
  13. conn.commit()
  14.  
  15. def proc1():
  16. conn = mysql.connector.connect(host='127.0.0.1',database='ae.udnikov',user='ae.udnikov',password='ae.udnikov')
  17. print(conn.is_connected())
  18. updateA(conn, 1, 1)
  19. updateB(conn, 2, 1)
  20.  
  21. def proc2():
  22. conn = mysql.connector.connect(host='127.0.0.1',database='ae.udnikov',user='ae.udnikov',password='ae.udnikov')
  23. print(conn.is_connected())
  24. updateB(conn, 1, 1)
  25. updateA(conn, 2, 1)
  26.  
  27. #conn = mysql.connector.connect(host='127.0.0.1',database='ae.udnikov',user='ae.udnikov',password='ae.udnikov')
  28. #print(conn.is_connected())
  29.  
  30.  
  31. #conn2 = mysql.connector.connect(host='127.0.0.1',database='ld.sinitsyna',user='ld.sinitsyna',password='ld.sinitsyna')
  32. t1 = threading.Thread(target=proc1, args=())
  33. t2 = threading.Thread(target=proc2, args=())
  34.  
  35. # start threads
  36. t1.start()
  37. #time.sleep(1)
  38. t2.start()
  39.  
  40.  
  41.  
  42. # join threads to the main thread
  43. t1.join()
  44. t2.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement