You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make PyGreSQL thread-safe on the connection level #16
f we want to go from module level to connection level thread-safety, we need to introduce a connection lock or mutex and wrap all the critical parts in the pgdb connection methods and the underlying C code source object methods.
We will need much better tests, including stress tests of the various connection methods with many threads that fail without the locks, before we could confidently claim to have threadsafety=2.
It's certainly doable, but a hard nut to crack that requires much effort.
Before deciding to tackle this, we should also collect some usage examples where threadsafety=2 would be important. When used with a web framework for instance, you usually have a thread-safe connection pool (e.g. provided by SQLAlchemy or DBUtils) and normally use a connection only within a single thread anyway.
Activity
Cito commentedon Feb 15, 2020
f we want to go from module level to connection level thread-safety, we need to introduce a connection lock or mutex and wrap all the critical parts in the pgdb connection methods and the underlying C code source object methods.
We will need much better tests, including stress tests of the various connection methods with many threads that fail without the locks, before we could confidently claim to have threadsafety=2.
It's certainly doable, but a hard nut to crack that requires much effort.
Before deciding to tackle this, we should also collect some usage examples where threadsafety=2 would be important. When used with a web framework for instance, you usually have a thread-safe connection pool (e.g. provided by SQLAlchemy or DBUtils) and normally use a connection only within a single thread anyway.
(copied from Trac)