From: Karl O. Pinc Date: Wed, 2 Oct 2024 16:57:00 +0000 (-0500) Subject: May as well trap out-of-memory all the time X-Git-Url: https://papio.biology.duke.edu/gitweb/?a=commitdiff_plain;h=023a02257f7c816db598bd4996248acd109ced94;p=pgwui_sql May as well trap out-of-memory all the time --- diff --git a/src/pgwui_sql/exceptions.py b/src/pgwui_sql/exceptions.py index 310a76e..6e9459b 100644 --- a/src/pgwui_sql/exceptions.py +++ b/src/pgwui_sql/exceptions.py @@ -86,14 +86,11 @@ class CSVError(SQLError): class MemoryError(SQLError): ''' - Error raised when we run out of memory generating on-screen results + Error raised when we run out of memory descr More description of the error detail Extra HTML describing the error ''' - def __init__(self, - descr=("Can't collect results for on-screen display" - '-- try downloading instead'), - detail=''): + def __init__(self, descr='', detail=''): super().__init__('Webserver out of memory', '', descr=descr, detail=detail) diff --git a/src/pgwui_sql/views/sql.py b/src/pgwui_sql/views/sql.py index 5dcabc9..23b3804 100644 --- a/src/pgwui_sql/views/sql.py +++ b/src/pgwui_sql/views/sql.py @@ -337,18 +337,24 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler): if cur.statusmessage is None: raise sql_ex.NoStatementsError(descr='No SQL statements executed') - if self.uf['download']: - try: - self.make_download(cur) - except csv.Error as ex: - raise sql_ex.CSVError(descr=f'The csv module reports: {ex}') - else: - try: + try: + if self.uf['download']: + try: + self.make_download(cur) + except csv.Error as ex: + raise sql_ex.CSVError( + descr=f'The csv module reports: {ex}') + else: self.make_sql_results(cur) - except MemoryError: - self.sql_results = [] - gc.collect() + except MemoryError: + self.sql_results = [] + gc.collect() + if self.uf['download_as'] == MANY_FILES_VALUE: raise sql_ex.MemoryError() + else: + raise sql_ex.MemoryError( + ("Can't collect results for on-screen display" + '-- try downloading instead')) def factory(self, ue): '''Make a db loader function from an UploadEngine.