diff options
author | Arun Isaac | 2022-09-27 17:26:27 +0530 |
---|---|---|
committer | Arun Isaac | 2022-09-29 16:15:46 +0530 |
commit | 55173799cf43660a655f23682d2c7f172cd515f8 (patch) | |
tree | fae1b6beab8a30ea91f1a7f28904cee809930b29 | |
parent | 495e02be4e3264c07e4ae89ccd2bc747bf2b6b59 (diff) | |
download | genenetwork2-55173799cf43660a655f23682d2c7f172cd515f8.tar.gz |
Close xapian database even if error occurs.
* wqflask/wqflask/database.py (xapian_database,
xapian_writable_database): Close xapian database even if error occurs.
-rw-r--r-- | wqflask/wqflask/database.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index 84c494c5..7e03a000 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -68,8 +68,10 @@ def xapian_database(): """Open xapian database read-only.""" # pylint: disable-next=invalid-name db = xapian.Database(get_setting("XAPIAN_DB_PATH")) - yield db - db.close() + try: + yield db + finally: + db.close() @contextlib.contextmanager @@ -77,5 +79,7 @@ def xapian_writable_database(): """Open xapian database for writing.""" # pylint: disable-next=invalid-name db = xapian.WritableDatabase(get_setting("XAPIAN_DB_PATH")) - yield db - db.close() + try: + yield db + finally: + db.close() |