I'm using a setup with nginx, uwsgi and SQLAlchemy. I recently switched from SQLObject and I'm now seeing strange random errors with SQLAlchemy. For instance:
sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically.
or:
sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column 'module.id'"
Is this some kind of behavior in SQLAlchemy which I'm not aware of? Can it be related to multiple processes/threads in uwsgi?
My uwsgi config file looks like this:
[uwsgi]
plugins=python
socket = 127.0.0.1:9002
wsgi-file = /thesystem/code/api.py
master = True
processes = 4
threads = 2
daemonize = /thesystem/logs/uwsgi.log
pidfile = /thesystem/uwsgi.pid
Very probably you are opening connections in /thesystem/code/api.py entry point.
That means your file descriptors will be inherited in workers and this does not work with sqlalchemy.
Add --lazy-apps (lazy-apps = true in your ini config) to load /thesystem/code/api.py in each worker instead of loading it in the master and then calling fork()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With