Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random errors with SQLAlchemy

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
like image 225
Markus Johansson Avatar asked Dec 04 '25 22:12

Markus Johansson


1 Answers

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()

like image 81
roberto Avatar answered Dec 06 '25 12:12

roberto