Django

Code

Ticket #4948: t.py

File t.py, 0.5 kB (added by loewis, 2 years ago)

Demonstration of race condition

Line 
1 import time, threading
2 from django.core.files.base import ContentFile
3 from django.core.files.storage import FileSystemStorage
4 temp_storage = FileSystemStorage(location="/tmp/files")
5
6 class 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
13 def save(data):
14     temp_storage.save('conflict', SlowFile(data))
15
16 threading.Thread(target=save, args=("Content 1",)).start()
17 #time.sleep(5)
18 save("Content2")