Question

What is the best way to share the SQLAlchemy session between my Pyramid application and Celery tasks while only instantiating the database engine once? I looked at this answer here, however, I don't want to have to create a another engine (that also happens to be global) since this is not very DRY. Also, during the Pyramid application startup the application .ini settings are passed into the main function so I would like to be able to configure the engine from this method but also have it available to all Celery tasks. Perhaps I am going about things the wrong way when it comes to Celery integration with Pyramid? Thanks for your help!

Was it helpful?

Solution

A major motivation behind using a message broker (celery) in the first place is that your web app and workers do not operate in the same process. Because of this, I'm going to suggest that you back up a bit and think of your system as separate processes that are not sharing the same database connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top