Thank you for your answer!

Function B is called after A. Literally:
/
//functionA()//
//functionB()/

It works fine when at the end of A /inserting_session.close_all()/ is called, but it is not very elegant (moreover it probably causes "MySQL server has gone away", but this is a different story).

Cheers!

On 03/22/2016 06:01 PM, Simon King wrote:
It sounds like the transaction for task B is starting before A's transaction has been committed, but you haven't really given enough information to debug further. How are you managing your sessions and transactions? Do B and A actually overlap (ie. does B start before A finishes)?

Simon

On Tue, Mar 22, 2016 at 4:07 PM, TomS. <pidev...@gmail.com <mailto:pidev...@gmail.com>> wrote:

    Could you advise what would be the best approach for the following
    problem.

    I have Flask-Celery task. Task consists of two functions (both are
    run in the same one Celery task): A and B. Function A calculates
    values which are then used by B function. Values are stored in DB
    (via SQLAlchemy). The problem is that, somehow, values from A are
    commited too slow (?), so function B has nothing to calc (whole
    task has to be called once again to get results from function B).

    I use below pattern:

    New values inside function A are commited this way:

    /try://
    //
    //    inserting_session.add(new_value)//
    //
    //    inserting_session.commit()//
    //
    //except Exception as e://
    //
    //    inserting_session.rollback()//
    //
    //and after all values are worked out://
    //
    //inserting_session.close()/


    Where:

    /class SQLSession(object)://
    //
    //    sql_engine = None//
    //
    //    @staticmethod//
    //    def sql_session()://
    //
    //        if SQLSession.sql_engine is None://
    //
    //            # create engine//
    //
    //            SQLSession.sql_engine = create_engine([...]),//
    //                pool_recycle=30//
    //                )//
    //
    //        # create a configured "Session" class//
    //
    //        insering_session_maker =
    sessionmaker(bind=SQLSession.sql_engine)//
    //
    //        # scope session//
    //
    //        inserting_session = scoped_session(insering_session_maker)//
    //
    //        # create a Session//
    //
    //        inserting_session_scoped = inserting_session()//
    //
    //        return inserting_session_scoped//
    //
    //
    //inserting_session = SQLSession.sql_session()/


    It works when instead of
    /
    //inserting_session.close()/

    close_all() is called:

    /inserting_session.close()/

    But it probably is not the best solution.

    The question is - how to deal with this issue?

    Cheers!
-- You received this message because you are subscribed to the Google
    Groups "sqlalchemy" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to sqlalchemy+unsubscr...@googlegroups.com
    <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
    To post to this group, send email to sqlalchemy@googlegroups.com
    <mailto:sqlalchemy@googlegroups.com>.
    Visit this group at https://groups.google.com/group/sqlalchemy.
    For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to