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 Invoking `Pool.recreate()` should be fine, but the documented pattern is to call `Engine.dispose` > How should I modify my app to make it compatible with both Waitress and Gunicorn? I've been trying to standardize this with pyramid_forkfsafe when I was deploying projects on uwsgi and gunicorn simultaneously: https://pypi.org/project/pyramid-forksafe/ https://github.com/jvanasco/pyramid_forksafe I don't know if the gunicorn is currently working, as I only work with uwsgi now and never got around to writing tests for gunicorn. Ideally, my package works like this: * it defines a new `ApplicationPostFork` event * you write your post-fork code in an event subscriber * the package invokes the event at the right time This allows you to just define the post-fork routine, and if everything goes correctly.... pyramid_forksafe will detect the correct post-fork event and invoke your routine. On Thursday, November 16, 2023 at 12:18:59 PM UTC-5 Theron Luhn wrote: > If you aren’t using `—preload` then gunicorn should load the application > fresh for each worker and you shouldn’t have any issues. > > If you are using preload, you have to recreate any existing connections on > fork. For SQLAlchemy I use: > > def after_fork(registry): > registry['db_engine'].pool.recreate() > > def includeme(config): > os.register_at_fork( > after_in_child=functools.partial(after_fork, config.registry), > ) > > > — Theron > > > > On Nov 16, 2023, at 7:41 AM, Laurent Daverio <ldav...@gmail.com> wrote: > > Hello list, > > this page seems to describe perfectly a problem I've stumbled on: > > > https://stackoverflow.com/questions/64995178/decryption-failed-or-bad-record-mac-in-multiprocessing > > 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. > > Before I start trying to develop a workaround, has anybody encountered the > problem? How should I modify my app to make it compatible with both > Waitress and Gunicorn? > > Thanks in advance, > > Laurent. > > -- > 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-discus...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/CAB7cU6z1DqHpEazrrJ1sPHmSPQvYtfkmeKfsJP_jLmsDyPA96w%40mail.gmail.com > > <https://groups.google.com/d/msgid/pylons-discuss/CAB7cU6z1DqHpEazrrJ1sPHmSPQvYtfkmeKfsJP_jLmsDyPA96w%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > > -- 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/459deec2-f880-494d-afc4-bfc300f15093n%40googlegroups.com.