[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multithread and locking issue

On Fri, May 15, 2020 at 9:20 AM Cameron Simpson <cs at cskk.id.au> wrote:
> On 14May2020 22:36, Stephane Tougard <stephane at sdf.org> wrote:
> >A multithreaded software written in Python is connected with a Postgres
> >database. To avoid concurrent access issue with the database, it starts
> >a thread who receive all SQL request via queue.put and queue.get (it
> >makes only insert, so no issue with the return of the SQL request).
> Just a remark that PostgreSQL ets callers work in parallel, just make
> multiple connections.

Seconded. If you know how many threads you're going to have, just open
that many connections. If not, there's a connection-pooling feature as
part of psycopg2 (if I'm not mistaken). This would be far far easier
to work with than a fragile queueing setup.