Commit a72aa6a4 by BoxuanXu

fix mysql bug

1 parent b660959d
Showing with 34 additions and 23 deletions
......@@ -42,8 +42,7 @@ output_layer = ""
pool_id = ""
err_msg = ""
post_url = "http://192.168l.1.127:1234/API"
#post_url = "http://192.168.1.244:5000/result"
post_url = "http://192.168.1.127:1234/API"
#init post info queue
Info_Queue = Queue.Queue()
......@@ -54,25 +53,32 @@ logging.basicConfig(
)
db_atlas = pymysql.connect("192.168.1.127","defaultUser","magician","seetaAtlas",3306)
curl_atlas = db_atlas.cursor()
curl_atlas_exe = db_atlas.cursor()
db_l = Mysql_lock()
lock_name = 'db_queue'
def get_path_from_db(modelid,seetanet_model):
#curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid)
ret = db_l.lock(lock_name,10)
if ret != True:
logging.info("Can't get lock! exit!")
quit()
db_l = Mysql_lock()
if db_l.db == '':
return None,None
#lock_name = 'db_queue'
#ret = db_l.lock(lock_name,10)
#if ret != True:
# logging.info("Can't get lock! exit!")
# quit()
ret = db_l._execute("select path from seetaAtlas.model where id='%s'" % modelid)
if ret is None:
return None,None
result_atlas = db_l.cursor.fetchall()
db_l.unlock(lock_name)
#db_l.unlock(lock_name)
#if ret != True:
# logging.info("Can't release lock! exit!")
# quit()
if len(result_atlas) != 1:
logging.info('get wrong mxnet model path')
......@@ -275,8 +281,5 @@ if __name__ == '__main__':
t.start();
app.run(host='0.0.0.0')
finally:
curl_atlas_exe.close()
curl_atlas.close()
db_atlas.close()
stbf_rls()
......@@ -16,19 +16,22 @@ logging.basicConfig(
format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
)
db_atlas = pymysql.connect("192.168.1.127","defaultUser","magician","seetaAtlas",3306)
class Mysql_lock:
def __init__(self):
self.db = db_atlas
self.cursor = db_atlas.cursor()
try:
db_atlas = pymysql.connect("192.168.1.127","defaultUser","magician","seetaAtlas",3306)
self.db = db_atlas
self.cursor = db_atlas.cursor()
except Exception,ex:
logging.info("Cannot connect to mysql server! Exception: %s", str(ex))
self.db = ''
self.cursor = ''
def _execute(self,sql):
cursor = self.db.cursor()
try:
ret = self.cursor.execute(sql)
return ret
except Exception,ex:
logging.info("Execute sql \"%s\" failed! Exception: %s", sql, str(ex))
#cursor.close()
return None
def lock(self, lockstr, timeout):
sql = "SELECT GET_LOCK('%s', %s)" % (lockstr, timeout)
......@@ -56,5 +59,10 @@ class Mysql_lock:
else:
logging.info("The lock '%s' did not exist.",lockstr)
return None
def __del__(self):
#Terminate the connection
if self.cursor != '':
self.cursor.close()
if self.db != '':
self.db.close()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!