Skip to content

Commit 3012ba2

Browse files
committed
more precices locking
1 parent a5be1f7 commit 3012ba2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ def __getConnection(self):
8181
if not idx in self.__conn_dict.keys():
8282
application_name = ";APP={0}-{1}".format(socket.gethostname(), idx)
8383
conn = pyodbc.connect(os.environ['SQLAZURECONNSTR_WWIF'] + application_name)
84+
self.__lock.acquire()
8485
self.__conn_dict.update( { idx: conn } )
86+
self.__lock.release()
8587
else:
88+
self.__lock.acquire()
8689
conn = self.__conn_dict[idx]
90+
self.__lock.release()
8791

8892
return (idx, conn)
8993

@@ -115,7 +119,7 @@ def executeQueryJSON(self, procedure, payload=None):
115119
cursor.commit()
116120
except Exception as e:
117121
self.__removeConnection(idx)
118-
if isinstance(e,pyodbc.ProgrammingError) or isinstance(e,pyodbc.OperationalError):
122+
if isinstance(e, pyodbc.ProgrammingError) or isinstance(e, pyodbc.OperationalError):
119123
if self.is_retriable(int(e.args[0])):
120124
raise
121125

0 commit comments

Comments
 (0)