0

I'm generating an excel file using xlwt and store it on datastore as blob property. But during the generation got this error "Timeout: The datastore operation timed out, or the data was temporarily unavailable.".

I have noticed that using xlutils we can update the exsisting files. I'm planning to do something like this, first time i will craete the file with half of my data and using another task will complete the file creation.

is there any better way to do this ?

Here is my current code:

from xlwt import *
wb = Workbook()
ws0 = wb.add_sheet("Sheet 1")

style = XFStyle()
style.font.name = 'Tahoma'   

currency_style = XFStyle()
currency_style.num_format_str = '$#,##0.00'       

ws0.write(0, 0, 'Col 1', style)
ws0.write(0, 1, 'Col 2', style)
ws0.write(0, 2, 'Col 3', style)
ws0.write(0, 3, 'Col 4', style)
rx = 1

for each in db_result:                
      ws0.write(rx, 0, each.col1, style)
      ws0.write(rx, 1, each.col2, style)
      ws0.write(rx, 2, each.col3, style)

      try:
          ws0.write(rx, 3, round(float(each.col4), 2), currency_style)
      except:
          ws0.write(rx, 3, each.col4, style)

      rx = rx + 1                
      db.delete(each)

buffer = StringIO.StringIO()
wb.save(buffer)
contents = buffer.getvalue()

f = myfile()
f.name = 'File 1'
f.file = db.Blob(contents)
f.put()
Nijin Narayanan
  • 2,269
  • 2
  • 27
  • 46

1 Answers1

1

If it's just a timeout issue where your code runs for longer then the timeout you could use a task instead, which gives you a 10 minute timeout instead of 60 seconds: Background work with the deferred library

from google.appengine.ext import deferred

  def do_something_expensive(a, b, c=None):
      logging.info("Doing something expensive!")
      # Do your work here

  # Somewhere else
  deferred.defer(do_something_expensive, "Hello, world!", 42, c=True)

So wrap your program up in a function you can pass to the defer method. Or look at using some of the other options like backends:

https://developers.google.com/appengine/docs/python/backends/

App engine Backends are instances of your application that are exempt from request deadlines and have access to more memory (up to 1GB) and CPU (up to 4.8GHz) than normal instances. They are designed for applications that need faster performance, large amounts of addressable memory, and continuous or long-running background processes. Backends come in several sizes and configurations, and are billed for uptime rather than CPU usage.

Paul Collingwood
  • 9,053
  • 3
  • 23
  • 36