Skip to content

Commit

Permalink
Don't commit when garbage-collected in a different thread (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Sep 6, 2024
1 parent bb27281 commit 7ee71f6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions jupyter_server_fileid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,14 @@ def __del__(self):
"""Cleans up `ArbitraryFileIdManager` by committing any pending
transactions and closing the connection."""
if hasattr(self, "con"):
self.con.commit()
self.con.close()
# If garbage collection happens in a different thread than the thread where
# the SQLite object was created, committing will fail anyway. We just ignore
# the exception if this is the case.
try:
self.con.commit()
self.con.close()
except sqlite3.ProgrammingError:
pass


class LocalFileIdManager(BaseFileIdManager):
Expand Down

0 comments on commit 7ee71f6

Please sign in to comment.