Took user restrictions off starting race reporting. Tried to improve sql writes to fix db locking error.

This commit is contained in:
tamservo
2025-04-21 16:47:05 -04:00
parent 069d2ca7d0
commit 4b636eed7a
2 changed files with 66 additions and 51 deletions

View File

@@ -5,6 +5,7 @@ import logging
import requests
import time
import sqlite3
import sys
from fastf1.signalr_aio import Connection
@@ -84,6 +85,7 @@ class SignalRClient:
"SessionData", "LapCount"]
self.debug = debug
self._db_is_open = False
self.filename = filename
self.filemode = filemode
self.timeout = timeout
@@ -91,7 +93,8 @@ class SignalRClient:
if not logger:
logging.basicConfig(
format="%(asctime)s - %(levelname)s: %(message)s"
format="%(asctime)s - %(levelname)s: %(message)s", \
stream=sys.stderr
)
self.logger = logging.getLogger('SignalR')
else:
@@ -107,11 +110,17 @@ class SignalRClient:
"""
#print(msg)
con = sqlite3.connect('messages.db')
cur = con.cursor()
cur.execute("insert into messages (message) values(?)", (msg,))
con.commit()
cur.close()
con.close()
try:
with con:
self._db_is_open = True
con.execute("insert into messages (message) values(?)", (msg,))
con.close()
self.db_is_open = False
except:
if con is not None:
con.close()
self._db_is_open = False
async def _on_do_nothing(self, msg):
# just do nothing with the message; intended for debug mode where some
@@ -186,7 +195,9 @@ class SignalRClient:
f"[v{fastf1.__version__}]")
await asyncio.gather(asyncio.ensure_future(self._supervise()),
asyncio.ensure_future(self._run()))
self._output_file.close()
#self._output_file.close()
while(self._db_is_open):
asyncio.sleep(1)
self.logger.warning("Exiting...")
def start(self):