Celery and SQLAlchemy - This result object does not return rows. It has been closed automatically

后端 未结 1 2091
傲寒
傲寒 2020-12-11 02:12

I have a celery project connected to a MySQL databases. One of the tables is defined like this:

class MyQueues(Base):
    __tablename__ = \'accepted_queues\'         


        
相关标签:
1条回答
  • 2020-12-11 02:55

    All together: any advise to skip these difficulties?

    yes. you absolutely cannot use a Session (or any objects which are associated with that Session), or a Connection, in more than one thread simultaneously, especially with MySQL-Python whose DBAPI connections are very thread-unsafe*. You must organize your application such that each thread deals with it's own, dedicated MySQL-Python connection (and therefore SQLAlchemy Connection/ Session / objects associated with that Session) with no leakage to any other thread.

    • Edit: alternatively, you can make use of mutexes to limit access to the Session/Connection/DBAPI connection to just one of those threads at a time, though this is less common because the high degree of locking needed tends to defeat the purpose of using multiple threads in the first place.
    0 讨论(0)
提交回复
热议问题