Skip to content

Commit 7f87ab3

Browse files
committed
hand-made connection pooling
1 parent 34c721a commit 7f87ab3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from flask_restful import reqparse, abort, Api, Resource
55
import json
66
import pyodbc
7+
import threading
78

89
# Initialize Flask
910
app = Flask(__name__)
@@ -13,10 +14,24 @@
1314
parser = reqparse.RequestParser()
1415
parser.add_argument('customer')
1516

17+
conn_index = 0
18+
conn_list = list()
19+
20+
for c in range(10):
21+
conn = pyodbc.connect(os.environ['SQLAZURECONNSTR_WWIF'])
22+
conn_list.append(conn)
23+
24+
def getConnection():
25+
global conn_index
26+
conn_index += 1
27+
if conn_index > 9:
28+
conn_index = 0
29+
return conn_list[conn_index]
30+
1631
class Queryable(Resource):
1732
def executeQueryJson(self, verb, payload=None):
1833
result = {}
19-
conn = pyodbc.connect(os.environ['SQLAZURECONNSTR_WWIF'])
34+
conn = getConnection()
2035
cursor = conn.cursor()
2136
entity = type(self).__name__.lower()
2237
procedure = f"web.{verb}_{entity}"

0 commit comments

Comments
 (0)