What's the correct way of creating listeners using a connection pool? #812
Answered
by
elprans
theo-brown
asked this question in
Q&A
-
I have a connection pool that exists for the duration of my program. What's the correct way of doing this? I need to avoid the listener_connection from being garbage collected. My current approach: listener_connection = await pool.acquire()
await listener_connection.add_listener('my_channel', my_callback_function)
...
# Program performs many other database operations, acquiring new connections from the pool as required.
... |
Beta Was this translation helpful? Give feedback.
Answered by
elprans
Aug 19, 2021
Replies: 1 comment 2 replies
-
That's the correct way. If you want something to live in Python, you must keep a reference to it. Most frameworks have a global state object you can write to (e.g. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
theo-brown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's the correct way. If you want something to live in Python, you must keep a reference to it. Most frameworks have a global state object you can write to (e.g.
app
in Flask).