Seler i SQLAlchemy - Ten obiekt wynikowy nie zwraca wierszy. Został zamknięty automatycznie

Mam projekt selera połączony z bazami danych MySQL. Jedna z tabel jest zdefiniowana w ten sposób:

class MyQueues(Base):
    __tablename__ = 'accepted_queues'

    id = sa.Column(sa.Integer, primary_key=True)
    customer = sa.Column(sa.String(length=50), nullable=False)
    accepted = sa.Column(sa.Boolean, default=True, nullable=False)
    denied = sa.Column(sa.Boolean, default=True, nullable=False)

Również w ustawieniach, które mam

THREADS = 4

I utknąłem w funkcjicode.py:

def load_accepted_queues(session, mode=None):

    #make query  
    pool = session.query(MyQueues.customer, MyQueues.accepted, MyQueues.denied)

    #filter conditions    
    if (mode == 'XXX'):
        pool = pool.filter_by(accepted=1)
    elif (mode == 'YYY'):
        pool = pool.filter_by(denied=1)
    elif (mode is None):
        pool = pool.filter(\
            sa.or_(MyQueues.accepted == 1, MyQueues.denied == 1)
            )

   #generate a dictionary with data
   for i in pool: #<---------- line 90 in the error
        l.update({i.customer: {'customer': i.customer, 'accepted': i.accepted, 'denied': i.denied}})

Podczas uruchamiania pojawia się błąd:

[20130626 115343] Traceback (most recent call last):
  File "/home/me/code/processing/helpers.py", line 129, in wrapper
    ret_value = func(session, *args, **kwargs)
  File "/home/me/code/processing/test.py", line 90, in load_accepted_queues
    for i in pool: #generate a dictionary with data
  File "/home/me/envs/me/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2341, in instances
    fetch = cursor.fetchall()
  File "/home/me/envs/me/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 3205, in fetchall
    l = self.process_rows(self._fetchall_impl())
  File "/home/me/envs/me/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 3174, in _fetchall_impl
    self._non_result()
  File "/home/me/envs/me/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 3179, in _non_result
    "This result object does not return rows. "
ResourceClosedError: This result object does not return rows. It has been closed automatically

Więc to głównie ta część

ResourceClosedError: This result object does not return rows. It has been closed automatically

a czasami także ten błąd:

DBAPIError: (Error) (, AssertionError ('Długość żądanego wyniku nie jest wymagana: nExpected = 1. Actual = 0. Position: 21. Długość danych: 21',)) 'SELECT accept_queues.customer AS accepted_queues_customer, accept_queues.accepted AS accepted_queues_accepted , accept_queues.denied AS accept_queues_denied nFROM accept_queues NEWHERE accept_queues.accepted =% s OR accept_queues.denied =% s '(1, 1)

Nie mogę poprawnie odtworzyć błędu, jak to zwykle ma miejsce podczas przetwarzania wielu danych. Próbowałem się zmienićTHREADS = 4 do1 i błędy zniknęły. W każdym razie nie jest to rozwiązanie, ponieważ potrzebuję liczby wątków, które mają być przechowywane4.

Ponadto jestem zdezorientowany potrzebą użycia

for i in pool: #<---------- line 90 in the error

lub

for i in pool.all(): #<---------- line 90 in the error

i nie mógł znaleźć właściwego wyjaśnienia tego.

Wszystko razem: radzę pominąć te trudności?

questionAnswers(1)

yourAnswerToTheQuestion