Question

Is there any way to share same transaction between two threads in a django-based code?

The problem is that I have 1.1's TestCase (those that wrap individual tests into transactions) that are intended to test code that is running in a different thread [a sort of asynchronous testing]. So these test create some data that is intended to be used by this second thread. Obviously, since this data is created within a transaction scope, it is not visible to the second thread. But since that should basically be the same connection to PgSQL (should it?) I hope there is a way to share this transaction scope so my second thread can access data being added within it?..

Any idea?

Database is PgSQL 8.3, driver is postgresql_psycopg2. Django — trunk.

Was it helpful?

Solution

I'd say that's impossible. To my knowledge, each thread has its own PostgreSQL session to be able to run concurrently. And given that PostgreSQL is an MVCC database, one thread will not have access to the other's changes, until the transaction is committed – which it won't be in the case of a Django 1.1 TestCase.

If you need to test stuff that runs concurrently, I'm pretty sure that you need to use a TransactionTestCase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top