#68 close responses

This commit is contained in:
Alok Saldanha
2022-06-20 21:29:19 -04:00
parent eaa157079c
commit 8d8a0a3483
+8 -2
View File
@@ -9,7 +9,6 @@
import datetime import datetime
import logging import logging
import re import re
import urllib.parse
from enum import Enum from enum import Enum
import psutil import psutil
@@ -22,6 +21,8 @@ from cellxgene_gateway.cellxgene_exception import CellxgeneException
from cellxgene_gateway.flask_util import querystring from cellxgene_gateway.flask_util import querystring
from cellxgene_gateway.util import current_time_stamp from cellxgene_gateway.util import current_time_stamp
logger = logging.getLogger(__name__)
class CacheEntryStatus(Enum): class CacheEntryStatus(Enum):
loaded = "loaded" loaded = "loaded"
@@ -111,7 +112,7 @@ class CacheEntry:
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
pass pass
logging.getLogger("cellxgene_gateway").info(f"terminated {terminated}") logger.info(f"terminated {terminated}")
self.status = CacheEntryStatus.terminated self.status = CacheEntryStatus.terminated
def rewrite_text_content(self, cellxgene_content): def rewrite_text_content(self, cellxgene_content):
@@ -169,6 +170,8 @@ class CacheEntry:
full_path = self.cellxgene_basepath() + subpath + querystring() full_path = self.cellxgene_basepath() + subpath + querystring()
try:
cellxgene_response = None
if request.method in ["GET", "HEAD", "OPTIONS"]: if request.method in ["GET", "HEAD", "OPTIONS"]:
cellxgene_response = get(full_path, headers=headers) cellxgene_response = get(full_path, headers=headers)
elif request.method == "PUT": elif request.method == "PUT":
@@ -203,4 +206,7 @@ class CacheEntry:
cellxgene_response.status_code, cellxgene_response.status_code,
resp_headers, resp_headers,
) )
finally:
if cellxgene_response is not None:
cellxgene_response.close()
return gateway_response return gateway_response