Ticket #4948: t.py

File t.py, 531 bytes (added by Martin v. Löwis, 16 years ago)

Demonstration of race condition

Line 
1import time, threading
2from django.core.files.base import ContentFile
3from django.core.files.storage import FileSystemStorage
4temp_storage = FileSystemStorage(location="/tmp/files")
5
6class SlowFile(ContentFile):
7 def chunks(self):
8 print "Asked for chunks"
9 time.sleep(2)
10 print "Returning chunks"
11 return super(ContentFile, self).chunks()
12
13def save(data):
14 temp_storage.save('conflict', SlowFile(data))
15
16threading.Thread(target=save, args=("Content 1",)).start()
17#time.sleep(5)
18save("Content2")
19
Back to Top