Managing global database connections when using --dev flag

Hello.
I am developing applications which listen to notify events in my postgres database. I create the connections and the classes which handle notifications outside my app.py and import them so that they do not get rebuilt for every session.

pseudocode:
create_conns.py

conn = db.connection()
user_of_conn = ConnUser(conn=conn) # listens for events on a thred

app.py

import panel as pn
from create_conns import user_of_conn
ui_stuff = UI(conn_dependent_thing=user_of_conn.watchable_thing)
pn.Column(
ui_stuff
).servable()

hope it makes sense. Normally, create_conns.py only runs once, and then each session gets some of its dependencies from it.

However, when I run my app in --dev mode, create_conns.py is run again and new connections are created, without the old ones actually getting closed. As I understand, the --dev reload somehow creates a new process, without killing the previous one? So connections build up until I ^C in my terminal. Is there any way to manage this better?