-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmtmc.py
More file actions
executable file
·36 lines (30 loc) · 742 Bytes
/
mtmc.py
File metadata and controls
executable file
·36 lines (30 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
multiple thread, multiple connections
"""
import threading
import mysql.connector
from random import uniform
from time import sleep
def read_user_from_db():
"""
read user info from db
"""
sleep(uniform(0, 1))
user_db = mysql.connector.connect(
host="localhost",
user="root",
passwd="123456",
database="users"
)
user_cursor = user_db.cursor()
user_cursor.execute("select * from userinfo")
return user_cursor.fetchall()
if __name__ == "__main__":
threads = []
for i in xrange(1000):
t = threading.Thread(target=read_user_from_db)
t.daemon = True
t.start()
threads.append(t)
for thread in threads:
thread.join()