Psycopg connection pool and threads not working properly
up vote
-2
down vote
favorite
I have a connection pool (ThreadedConnectionPool) and threads that when I'm executing I get a connection from the pool, does all it's stuff and then release connection by putconn(), but if I do this inside the thread it doesn't release properly the connection and gets "connection pool exhausted". I tryed doing this outside the thread and everything's fine. I passed the connection pool to the thread's executed function but it doesn't work anyway. Any idea? Thank you.
dbconn_pool = psycopg2.pool.ThreadedConnectionPool(minconn=1, maxconn=3,
host="XXX",
port="XXX",
dbname="XXX",
user="XXX",
password="XXX")
def processing_informations(conn_pool):
db_connection = conn_pool.getconn()
db_connection.set_session(readonly=True, autocommit=True)
cur = db_connection.cursor(cursor_factory=RealDictCursor)
.....more....
conn_pool.putconn(db_connection)
def start_processor():
new_thread = threading.Thread(target=self.processing_informations, args=[dbconn_pool])
new_thread.daemon = True
new_thread.start()
while true:
start_processor()
sleep(100)
python multithreading connection-pooling psycopg2
add a comment |
up vote
-2
down vote
favorite
I have a connection pool (ThreadedConnectionPool) and threads that when I'm executing I get a connection from the pool, does all it's stuff and then release connection by putconn(), but if I do this inside the thread it doesn't release properly the connection and gets "connection pool exhausted". I tryed doing this outside the thread and everything's fine. I passed the connection pool to the thread's executed function but it doesn't work anyway. Any idea? Thank you.
dbconn_pool = psycopg2.pool.ThreadedConnectionPool(minconn=1, maxconn=3,
host="XXX",
port="XXX",
dbname="XXX",
user="XXX",
password="XXX")
def processing_informations(conn_pool):
db_connection = conn_pool.getconn()
db_connection.set_session(readonly=True, autocommit=True)
cur = db_connection.cursor(cursor_factory=RealDictCursor)
.....more....
conn_pool.putconn(db_connection)
def start_processor():
new_thread = threading.Thread(target=self.processing_informations, args=[dbconn_pool])
new_thread.daemon = True
new_thread.start()
while true:
start_processor()
sleep(100)
python multithreading connection-pooling psycopg2
2
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I have a connection pool (ThreadedConnectionPool) and threads that when I'm executing I get a connection from the pool, does all it's stuff and then release connection by putconn(), but if I do this inside the thread it doesn't release properly the connection and gets "connection pool exhausted". I tryed doing this outside the thread and everything's fine. I passed the connection pool to the thread's executed function but it doesn't work anyway. Any idea? Thank you.
dbconn_pool = psycopg2.pool.ThreadedConnectionPool(minconn=1, maxconn=3,
host="XXX",
port="XXX",
dbname="XXX",
user="XXX",
password="XXX")
def processing_informations(conn_pool):
db_connection = conn_pool.getconn()
db_connection.set_session(readonly=True, autocommit=True)
cur = db_connection.cursor(cursor_factory=RealDictCursor)
.....more....
conn_pool.putconn(db_connection)
def start_processor():
new_thread = threading.Thread(target=self.processing_informations, args=[dbconn_pool])
new_thread.daemon = True
new_thread.start()
while true:
start_processor()
sleep(100)
python multithreading connection-pooling psycopg2
I have a connection pool (ThreadedConnectionPool) and threads that when I'm executing I get a connection from the pool, does all it's stuff and then release connection by putconn(), but if I do this inside the thread it doesn't release properly the connection and gets "connection pool exhausted". I tryed doing this outside the thread and everything's fine. I passed the connection pool to the thread's executed function but it doesn't work anyway. Any idea? Thank you.
dbconn_pool = psycopg2.pool.ThreadedConnectionPool(minconn=1, maxconn=3,
host="XXX",
port="XXX",
dbname="XXX",
user="XXX",
password="XXX")
def processing_informations(conn_pool):
db_connection = conn_pool.getconn()
db_connection.set_session(readonly=True, autocommit=True)
cur = db_connection.cursor(cursor_factory=RealDictCursor)
.....more....
conn_pool.putconn(db_connection)
def start_processor():
new_thread = threading.Thread(target=self.processing_informations, args=[dbconn_pool])
new_thread.daemon = True
new_thread.start()
while true:
start_processor()
sleep(100)
python multithreading connection-pooling psycopg2
python multithreading connection-pooling psycopg2
edited Nov 15 at 13:28
asked Nov 15 at 11:57
Giuseppe
6912
6912
2
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29
add a comment |
2
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29
2
2
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318999%2fpsycopg-connection-pool-and-threads-not-working-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You'd provide example code to clarify whot you are doing. Or even better a Minimal, Complete, and Verifiable example
– Selaron
Nov 15 at 12:08
i added a basic example, the project is not properly like this but i tried to expose the parte the is getting the issue
– Giuseppe
Nov 15 at 13:29