Browse Source

close db connection to avoid locking tables while pyapi is running

Pi 1 year ago
parent
commit
12d252e3e0
1 changed files with 5 additions and 2 deletions
  1. 5 2
      rest/pyapi.py

+ 5 - 2
rest/pyapi.py

@@ -17,8 +17,11 @@ heading = """<?xml version="1.0" encoding="UTF-8"?>
 
 
 @route('/pyapi/random')
 @route('/pyapi/random')
 def index():
 def index():
-    with conn.cursor() as cur:
-        xml = cur.execute(statement).fetchone()[0]
+    try:
+        with conn.cursor() as cur:
+            xml = cur.execute(statement).fetchone()[0]
+    finally:
+        conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
     response.content_type = 'application/xhtml+xml; charset=utf-8'
     return f"{heading}{xml}"
     return f"{heading}{xml}"