Commit a72aa6a4 by BoxuanXu

fix mysql bug

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