Simon Wu
Simon Wu

Reputation: 1

Turbogears2 with MySQL db not update tables in multi threads

I am using turbogears2 with MySQL db. With the same code, single thread case can update/write to the tables. But thread thread has no error, however, no write is successful.

Outside turbogears2, multi threads can write to the tables no problems.

No error or complaints with multi thread with tg2. Just no successful write to the table.

I will be very grateful if anyone using tg2 can advise.

Upvotes: 0

Views: 78

Answers (1)

p_piotr3k
p_piotr3k

Reputation: 11

With default configuration settings, in a regular request/response cycle, TuborGears2 enables a transaction manager to automatically commit changes to the database when a controller has finished processing a request.

This is introduced in the Wiki in 20 Minutes tutorial:

[...] you would usually need to flush the SQLAlchemy Unit of Work and commit the currently running transaction, those are operations that TurboGears2 transaction management will automatically do for us.

You don’t have to do anything to use this transaction management system, it should just work.

However, for everything that is outside a regular request/response cycle, for example a stream, or a different thread like a scheduler, manually flushing the session and committing the transaction is required. This is performed with DBSession.flush() and transaction.commit().

Upvotes: 1

Related Questions