I have a function readLatestOp(), the function interacts with mongodb and sqlite. I want to run multiple instance of this function concurrently to test my concurrency control mechanism. How do I go about this. So I want to call readLatestOp() maybe 10 times runing them concurrently
def readLatestOp():
try:
account = raw_input("Enter the account ID: ")
started = time.clock()
calSTime = datetime.datetime.utcnow()
print(calSTime)
cursor = conn.execute("select * from SNAPSHOT_ISOLATION where DEST_ID = ? AND T_COMMIT ISNULL OR SOURCE_ID = ? and T_COMMIT ISNULL", (account, account))
result = (cursor.fetchone())
while time.clock() - started < 5 and result is not None:
cursor = conn.execute("select * from SNAPSHOT_ISOLATION where DEST_ID = ? AND T_COMMIT ISNULL OR SOURCE_ID = ? and T_COMMIT ISNULL", (account, account))
result = (cursor.fetchone())
findLatest = db.accounts.find_one({"_id" : account})
calFTime = datetime.datetime.utcnow()
print(calFTime)
except ValueError as err:
print(err)
print('You entered a wrong error')
sys.exit(1)
if result is not None:
print("Data not avaialable")
else:
return findLatest
Aucun commentaire:
Enregistrer un commentaire