I want to compare my distributed database and postgresql. So I need to simulate multi-user SQL operations on postgresql using Python.
Can I use the mutliprocessing module?
here is my code
# encoding=utf-8
import datetime
import multiprocessing
import psycopg2
def exe(cmd):
conn = psycopg2.connect("dbname = test user = pj password = dbrgdbrg")
cur = conn.cursor()
try:
sql = "SELECT id FROM test WHERE ST_MAKEENVELOPE(118,38,119,39,4326) && wkb_geometry;"
cur.execute(sql)
print cur.fetchone()
except Exception, e:
print e
if __name__ == "__main__":
cmds=range(5)
for cmd in cmds:
p = multiprocessing.Process(target=exe,args=(cmd,))
p.start()
p.join()
But I don't know if it is correct? What should I do if I wanted to create random parameter to my SQL statements?