In SQLAlchemy, if using NullPool, do I need to instantiate the Engine object only once?

Viewed 98

In SQLAlchemy's docs, they mention that you should instantiate an Engine object (by calling create_engine) only once (per DB URL) in the lifetime of your application, as "the Engine is most efficient when created just once at the module level of an application".

My question is: if I'm creating the engine disabling pooling (using NullPool) is there still advantages from instantiating it only once per application lifetime? The reason I'm using NullPool is that we were having some issues related to multiprocessing, and that was one of the things suggested in SQLAlchemy's docs for solving it.

My understanding is that by not using pooling, we're not keeping DB connections open after they are used, so what would be the potential downsides of calling create_engine for each query that gets run?

I'm asking because I'm working with a codebase that right now instantiates the engine object for each query that it will run, so I'm trying to assess whether there are significant benefits from changing that to instantiate the engine only once that would make it worth the time and effort that will be required for this refactoring.

0 Answers
Related