0

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.

Conley Owens
  • 8,691
  • 5
  • 30
  • 43
  • Looking back at this question, I really needed to qualify the word atomic. I was more interested in whether or not any django action can happen in between, rather than if something goes wrong will everything get rolled back. – Conley Owens Jun 26 '11 at 05:07

2 Answers2

0

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.

Community
  • 1
  • 1
Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
0

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
  • 148,955
  • 89
  • 346
  • 502