O
O
OCCASS OCCASSOVICH2022-02-26 21:59:10
Python
OCCASS OCCASSOVICH, 2022-02-26 21:59:10

How to access the database if it is occupied by another program?

I'm having trouble accessing the database from another program.
I have a multiprocessing application that uses a SQLite and SqlAlchemy database.
This is what the engine looks like:

engine = create_engine(f'sqlite:///{DATABASE_PATH}', poolclass=QueuePool)

I decided to access the database, also through SqlAlchemy from another program, and the Database is locked error appears.
How to solve this problem?
I have an idea to make some kind of API, for example, on flask, so that programs can access it through requests, but maybe there is something easier?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2022-02-26
@OCCASS

No way, SQLite is not designed for concurrent access.

S
SKEPTIC, 2022-02-26
@pro100chel

Use subds that have competitive access - Mysql, Postgres, etc.
From crutches - write a third program, which will receive requests for input, and it will return a response. Passing requests by some queue or via http or sockets.
But if you cannot raise a normal subd, you are unlikely to raise the same rabbitmq

S
shurshur, 2022-02-26
@shurshur

Alternatively, a lock file is created next to the base, and all processes that work with it place an exclusive lock before any operation with the base, and after it is completed, it is released. But still I recommend switching to an independent DBMS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question