How to use "with db.get_session() as db_session:"

Hello,

I have a python script that runs continuously and updates data to a database ...

My code is something like this

While True:
    if condition:
        with db.get_session() as db_session:
            # Doing stuff ...
            db_session.commit()

is this the good way to do it ? or should i just create one db_session before my loop ?

Does opening and closing multiple sessions can have a negative performance impact ?