I am trying to run a celery_beat job that kicks off a bunch of parallel jobs, but am getting the error: ResourceClosedError: This result object does not return rows. It has been closed automatically.
Here are my relevant files. Notice that I am using a scoped_session:
#db.py
engine = create_engine(SETTINGS['DATABASE_URL'], pool_recycle=3600, pool_size=10)
db_session = scoped_session(sessionmaker(
autocommit=False, autoflush=False, bind=engine))
#tasks.py
from db import db_session
@app.task
def db_task(pid):
db_session()
r = db_session.query(exists().where(RSSSummary.id == pid)).scalar()
print pid, r
db_session.remove()
@app.task
def sched_test():
ids =[0, 1]
db_task.delay(ids[0])
db_task.delay(ids[1])
And then when I try initiate sched_test, like so:
>>> tasks.sched_test.delay()
DatabaseError: (psycopg2.DatabaseError) error with status PGRES_TUPLES_OK and no message from the libpq
and
ResourceClosedError: This result object does not return rows. It has been closed automatically.
I believe I am using scoped_sessions properly.
Any suggestions?