Question

I got timeout error on my GAE server when it tries to send large files to an EC2 REST server. I found Backends Python API would be a good solution to my example but I had some problems on configuring it.

Following some instructions, I have added a simple backends.yaml in my project folder. But I still received the following error, which seems like I failed to create a backend instance.

  File "\Google\google_appengine\google\appengine\api\background_thread\background_thread.py", line 84, in start_new_background_thread
    raise ERROR_MAP[error.application_error](error.error_detail)
FrontendsNotSupported

Below is my code, and my question is:

  1. Currently, I got timeout error in OutputPage.py, how do I let this script run on a backend instance?

update

Following Jimmy Kane's suggestions, I created a new script przm_batchmodel_backend.py for the backend instance. After staring my GAE, now it I have two ports (a default and a backend) running my site. Is that correct?

app.yaml

- url: /backend.html
  script: przm_batchmodel.py

backends.yaml

backends:
- name: mybackend
  class: B1
  instances: 1
  options: dynamic

OutputPage.py

from przm import przm_batchmodel
from google.appengine.api import background_thread

    class OutputPage(webapp.RequestHandler):
        def post(self):
            form = cgi.FieldStorage()
            thefile = form['upfile']

            #this is the old way to initiate calculations
            #html= przm_batchmodel.loop_html(thefile)  

            przm_batchoutput_backend.przmBatchOutputPageBackend(thefile)

            self.response.out.write(html)
    app = webapp.WSGIApplication([('/.*', OutputPage)], debug=True)

przm_batchmodel.py

    def loop_html(thefile):
        #parses uploaded csv and send its info. to the REST server, the returned value is a html page. 
        data= csv.reader(thefile.file.read().splitlines())
        response = urlfetch.fetch(url=REST_server, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60)   
        return response

przm_batchmodel_backend.py

    class BakendHandler(webapp.RequestHandler):
        def post(self):
            t = background_thread.BackgroundThread(target=przm_batchmodel.loop_html, args=[thefile])
            t.start()
    app = webapp.WSGIApplication([('/backend.html', BakendHandler)], debug=True)
Was it helpful?

Solution

You need to create an application 'file'/script for the backend to work. Just like you do with the main.

So something like:

app.yaml

- url: /backend.html
  script: przm_batchmodel.py

and on przm_batchmodel.py

class BakendHandler(webapp.RequestHandler):
    def post(self):

        html = 'test'
        self.response.out.write(html)
app = webapp.WSGIApplication([('/backend.html', OutputPage)], debug=True)

May I also suggest using the new feature modules which are easier to setup?

Edit due to comment

Possible the setup was not your problem.

From the docs

Code running on a backend can start a background thread, a thread that can "outlive" the request that spawns it. They allow backend instances to perform arbitrary periodic or scheduled tasks or to continue working in the background after a request has returned to the user.

You can only use backgroundthread on backends.

So edit again. Move the part of the code that is:

 t = background_thread.BackgroundThread(target=przm_batchmodel.loop_html, args=[thefile])
 t.start()
 self.response.out.write(html)

To the backend app

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top