> Namely, if you deploy with Gunicorn a Pyramid + PostgreSQL app based on 
the standard cookiecutter, you will run into problems, because the 
connection to the DB can't be shared between the processes, so each process 
needs to have its own connection to the DB.

I forgot to mention...

This should not happen. Do you know which cookiecutter you used, and when?  
This should not happen in the most recent cookiecutter.

The cookiecutter works by adding a transaction/thread safe session to each 
request: 
https://github.com/Pylons/pyramid-cookiecutter-starter/blob/latest/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.repo_name%7D%7D/sqlalchemy_models/__init__.py#L87-L127

It also requires pyramid_tm, which will cleanup the connections at the end 
of the request lifecycle.  If you decide to not use pyramid_tm, then you'll 
have to use a cleanup routine like this one when you grab the request.  
This was one the pattern in the pyramid cookiecutter, but it was taken out 
because pyramid_tm effectively does that itself.

  
  
https://github.com/jvanasco/pyramid_oauthlib_lowlevel/blob/main/tests/oauth2_app/model/__init__.py#L71-L77

The only way the connection pool sharing should be able to happen is if you 
grabbed a database connection before the fork - like during application 
setup, which would then require a call to Engine.dispose.

If you are not consciously grabbing a database connection before the fork, 
you should do a code audit to figure out where the first connection is 
being made and how it is recycled, as the last few versions of the 
cookiecutter do defend against this behavior.




On Tuesday, November 21, 2023 at 1:06:43 AM UTC-5 Mike Orr wrote:

> On Mon, Nov 20, 2023 at 4:14 PM Jonathan Vanasco <jvan...@gmail.com> 
> wrote:
> >
> > SQLAlchemy supports this via `Engine.dispose()`, which is the documented 
> way of handling a post-fork connection:
> >
> > https://docs.sqlalchemy.org/en/13/core/connections.html#engine-disposal
>
> Yes, that sounds familiar.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/984f5ea0-5d10-416b-83f0-c6d19d30ad9dn%40googlegroups.com.

Reply via email to