views:

38

answers:

2

I have a function that writes file to disk. Using a concurrent server, it is possible (likely even) that this function could be called by two threads, concurrently. Looking at the source code, it seems that wrapping my function up in django.db.transaction will keep both my db operations and my non-db operations atomic. Is this correct?

UPDATE: What I would really like is not just a yes or no answer but a link to an explanation or a comment on what exactly the thread stuff going on in enter_transaction_management in django.db.transaction.py is doing.

A: 

NO it won't. Transactions are specific to the database, and are handled much differently than IPC locking.

You should add a process identifier to the file you are writing to to make sure it is unique. Otherwise lock the file to make sure you are the only one writing to it.

Byron Whitlock
A: 

By "Django transaction", I assume that you mean the transactions in django.db.transactions?

And, if that's the case - no. They only pertain to database transactions (ie, they will only issue a BEGIN then a COMMIT or ROLLBACK).

David Wolever