Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from messages import SayText2
  2. from threaded_mysql import ThreadedMySQL
  3. import pymysql.cursors
  4.  
  5. # ON = No lag | OFF = Server freeze
  6. use_threaded_mysql = 1
  7.  
  8. connection = pymysql.connect(host="localhost",
  9.                                   user="root",
  10.                                   password="123",
  11.                                   db="my_database",
  12.                                   charset="utf8",
  13.                                   cursorclass=pymysql.cursors.DictCursor)
  14. cursor = connection.cursor()
  15.  
  16.  
  17. def load():
  18.     # Put use_threaded_mysql = 1 to test the difference
  19.     if not use_threaded_mysql:
  20.  
  21.         # Executes the query 1000 times
  22.         for x in range(1000):
  23.  
  24.             cursor.execute('SELECT name FROM my_database')
  25.             data = cursor.fetchone()
  26.             # Prints it out (not necessary tho)
  27.             SayText2('Name: {}'.format(data['name'])).send()
  28.     else:
  29.         # Class
  30.         TSQL = ThreadedMySQL()
  31.         # Use the connection already created
  32.         TSQL.connect_use(connection)
  33.         # Starts the queuehandler
  34.         TSQL.handlequeue_start()
  35.  
  36.         for x in range(1000):
  37.             TSQL.fetchone('SELECT name FROM my_database', callback=test)
  38.  
  39.  
  40. def test(data):
  41.     SayText2('Name: {}'.format(data['name'])).send()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement