fix db locked error
This commit is contained in:
parent
064576e225
commit
ba5e00b24b
@ -36,7 +36,6 @@ class ArchiveSynchronizer(Component):
|
|||||||
self.gcs_bucket = None
|
self.gcs_bucket = None
|
||||||
|
|
||||||
@db.connection_context()
|
@db.connection_context()
|
||||||
@db.atomic()
|
|
||||||
def _get(self):
|
def _get(self):
|
||||||
for record in Archive.select().where((Archive.archived != True) | (Archive.uploaded != True)): # using "is not True" breaks the query.
|
for record in Archive.select().where((Archive.archived != True) | (Archive.uploaded != True)): # using "is not True" breaks the query.
|
||||||
if not self.simulate:
|
if not self.simulate:
|
||||||
|
|||||||
87
src/test/tdb.py
Normal file
87
src/test/tdb.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import faulthandler
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
from uuid import uuid4 as uuid
|
||||||
|
|
||||||
|
from peewee import AutoField, Model, TextField
|
||||||
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
|
from PyQt5.QtCore import QObject, QThread, QTimer
|
||||||
|
|
||||||
|
# SETUP QUITTING ON CTRL+C
|
||||||
|
signal.signal(signal.SIGINT, quit)
|
||||||
|
|
||||||
|
# SETUP FAULTHANDLER
|
||||||
|
faulthandler.enable(file=sys.stderr, all_threads=True)
|
||||||
|
|
||||||
|
|
||||||
|
db = SqliteExtDatabase(
|
||||||
|
"/tmp/tdb.sqlite3",
|
||||||
|
pragmas={ # see https://www.sqlite.org/pragma.html
|
||||||
|
"auto_vacuum": 1,
|
||||||
|
"busy_timeout": 5000,
|
||||||
|
"cache_size": round(-64e3),
|
||||||
|
"foreign_keys": 1,
|
||||||
|
"ignore_check_constraints": 0,
|
||||||
|
"journal_mode": "wal",
|
||||||
|
"synchronous": 0,
|
||||||
|
},
|
||||||
|
timeout=5
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseModel(Model):
|
||||||
|
"""A base model that will use our Sqlite database."""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
global db
|
||||||
|
database = db
|
||||||
|
|
||||||
|
|
||||||
|
class Data(BaseModel):
|
||||||
|
id = AutoField(primary_key=True, unique=True, null=False)
|
||||||
|
data = TextField(null=True, default=lambda: uuid().hex)
|
||||||
|
|
||||||
|
|
||||||
|
models_reference = {
|
||||||
|
"data": Data,
|
||||||
|
}
|
||||||
|
|
||||||
|
db.connect()
|
||||||
|
db.create_tables(list(models_reference.values()))
|
||||||
|
|
||||||
|
|
||||||
|
class Threaded(QObject):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self._timer = QTimer()
|
||||||
|
|
||||||
|
@db.connection_context()
|
||||||
|
# @db.atomic()
|
||||||
|
def start(self):
|
||||||
|
while True:
|
||||||
|
data = Data()
|
||||||
|
data.save()
|
||||||
|
print(str(int(QThread.currentThreadId())), data.id, flush=True)
|
||||||
|
# QThread.msleep(2000)
|
||||||
|
|
||||||
|
|
||||||
|
components = {1: Threaded()}
|
||||||
|
threads = {}
|
||||||
|
for component_name in components:
|
||||||
|
threads[component_name] = QThread()
|
||||||
|
threads[component_name].setTerminationEnabled(True)
|
||||||
|
components[component_name].moveToThread(threads[component_name])
|
||||||
|
for component_name, thread in threads.items():
|
||||||
|
component = components[component_name]
|
||||||
|
thread.started.connect(component.start)
|
||||||
|
thread.start()
|
||||||
|
if "--debugger-workaround" in sys.argv:
|
||||||
|
QApplication.processEvents()
|
||||||
|
# QThread.msleep(1000)
|
||||||
|
QApplication.processEvents()
|
||||||
|
while True:
|
||||||
|
data = Data()
|
||||||
|
data.save()
|
||||||
|
print("main", data.id, flush=True)
|
||||||
|
# QThread.msleep(2000)
|
||||||
Loading…
Reference in New Issue
Block a user