Last active
May 4, 2022 23:14
-
-
Save alexkiro/783c7ae639b40a3320ad8d6e7f245d8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
def task(): | |
try: | |
db = MySQLdb.connect( | |
db="my_db", user=user, passwd=passwd, | |
host=host, | |
ssl={ | |
"key": "/etc/ssl/private/client-key.pem", | |
"cert": "/etc/ssl/private/client-cert.pem", | |
} | |
) | |
c = db.cursor() | |
except Exception as e: | |
print e | |
return | |
try: | |
c.execute("select * from invalid_table") | |
except Exception as e: | |
print e | |
finally: | |
c.close() | |
db.close() | |
import threading | |
ts = [] | |
for i in range(10): | |
t = threading.Thread(target=task) | |
t.start() | |
ts.append(t) | |
for t in ts: | |
t.join() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
def task(): | |
try: | |
db = MySQLdb.connect( | |
db="my_db", user=user, passwd=passwd, | |
host=host, | |
ssl={ | |
"key": "/etc/ssl/private/client-key.pem", | |
"cert": "/etc/ssl/private/client-cert.pem", | |
} | |
) | |
c = db.cursor() | |
except Exception as e: | |
print e | |
return | |
try: | |
c.execute("select count(*) from example_table") | |
print c.fetchall() | |
except Exception as e: | |
print e | |
finally: | |
c.close() | |
db.close() | |
import threading | |
ts = [] | |
for i in range(10): | |
t = threading.Thread(target=task) | |
t.start() | |
ts.append(t) | |
for t in ts: | |
t.join() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymysql | |
def task(): | |
try: | |
db = pymysql.connect( | |
db="my_db", user=user, passwd=passwd, | |
host=host, | |
ssl={ | |
"key": "/etc/ssl/private/client-key.pem", | |
"cert": "/etc/ssl/private/client-cert.pem", | |
} | |
) | |
c = db.cursor() | |
except Exception as e: | |
print e | |
return | |
try: | |
c.execute("select count(*) from example_table") | |
print c.fetchall() | |
except Exception as e: | |
print e | |
finally: | |
c.close() | |
db.close() | |
import threading | |
ts = [] | |
for i in range(10): | |
t = threading.Thread(target=task) | |
t.daemon = True | |
t.start() | |
ts.append(t) | |
for t in ts: | |
t.join() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlalchemy | |
def task(): | |
try: | |
engine = sqlalchemy.create_engine( | |
'mysql://%s:%s@%s/' % | |
(user, passwd, host), | |
connect_args={ | |
"ssl": { | |
"key": "/etc/ssl/private/client-key.pem", | |
"cert": "/etc/ssl/private/client-cert.pem", | |
} | |
} | |
) | |
session = sqlalchemy.orm.sessionmaker(bind=engine)() | |
except Exception as e: | |
print e | |
return | |
try: | |
print session.query(Model).count() | |
except Exception as e: | |
print e | |
finally: | |
session.close() | |
import threading | |
ts = [] | |
for i in range(10): | |
t = threading.Thread(target=task) | |
t.daemon = True | |
t.start() | |
ts.append(t) | |
for t in ts: | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment