I am using the files api quite heavily. One thing I have noticed is
about 15% of the time I will not get a blob_key returned after running
file.finalize(), hence when I try to set my blobreference property in
a datastore entity it is set to null. Here is my code:
file_store =
models.FileStore.get_or_insert('master_guest_list')
file_name = files.blobstore.create(mime_type='application/
octet-stream', _blobinfo_uploaded_filename='master_guest_list.csv')
blob_writer = files.open(file_name, 'a')
new_line =
'Name,Alternate,Title,Company,Type,Host,Event,Date,Market\r\n,,,,,,,,,
\r\n'
blob_writer.write(new_line)
cursor = None
while True:
q = models.Guests.all()
if cursor:
q.with_cursor(cursor)
guests = q.fetch(100) #100 at a time to avoid
timeouts
if guests:
cursor = q.cursor()
for guest in guests:
new_line = str( '%s,%s,%s,%s,%s,%s,%s,%s,%s\r\n' %
(guest.name,
guest.alternate,
guest.title,
guest.company,
guest.type,
guest.host,
guest.event_name,
guest.event_date,
guest.event_market) )
blob_writer.write(new_line)
else:
break
blob_writer.close()
files.finalize(file_name)
#sleep to make sure key is ready
time.sleep(2)
blob_key = files.blobstore.get_blob_key(file_name)
file_store.blob_key = blob_key
if not file_store.blob_key:
logging.error('key failed %s' % str(blob_key))
#make sure it runs again
self.error(500)
file_store.put()
Notice above:
files.finalize(file_name)
#sleep to make sure key is ready
time.sleep(2)
I had to add the time.sleep(2) in order to avoid this issue. I cannot
be the only one experiencing this. This happens as regular as the sun
comes up if I don't time.sleep(2) at least, even then I still get an
error about 1% of the time. Anybody have any suggestions? Or anyone
else experiencing this?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.