mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't hang in db.execute_write_fn() if connection fails
Closes #935 Refs https://github.com/simonw/latest-datasette-with-all-plugins/issues/3
This commit is contained in:
parent
13b3b51087
commit
b86f94883b
3 changed files with 32 additions and 6 deletions
|
|
@ -89,14 +89,22 @@ class Database:
|
|||
def _execute_writes(self):
|
||||
# Infinite looping thread that protects the single write connection
|
||||
# to this database
|
||||
conn = self.connect(write=True)
|
||||
conn_exception = None
|
||||
conn = None
|
||||
try:
|
||||
conn = self.connect(write=True)
|
||||
except Exception as e:
|
||||
conn_exception = e
|
||||
while True:
|
||||
task = self._write_queue.get()
|
||||
try:
|
||||
result = task.fn(conn)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
result = e
|
||||
if conn_exception is not None:
|
||||
result = conn_exception
|
||||
else:
|
||||
try:
|
||||
result = task.fn(conn)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
result = e
|
||||
task.reply_queue.sync_q.put(result)
|
||||
|
||||
async def execute_fn(self, fn):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue