Skip to content

Commit 7ee71f6

Browse files
Don't commit when garbage-collected in a different thread (#81)
1 parent bb27281 commit 7ee71f6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

jupyter_server_fileid/manager.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,14 @@ def __del__(self):
386386
"""Cleans up `ArbitraryFileIdManager` by committing any pending
387387
transactions and closing the connection."""
388388
if hasattr(self, "con"):
389-
self.con.commit()
390-
self.con.close()
389+
# If garbage collection happens in a different thread than the thread where
390+
# the SQLite object was created, committing will fail anyway. We just ignore
391+
# the exception if this is the case.
392+
try:
393+
self.con.commit()
394+
self.con.close()
395+
except sqlite3.ProgrammingError:
396+
pass
391397

392398

393399
class LocalFileIdManager(BaseFileIdManager):

0 commit comments

Comments
 (0)