I am having a problem with the AppEngine serving me a blank page every time the instance is loaded.
It is similar problem already covered here, however, there was no constructive solution mentioned that would help my case.
As there are no errors in the console, this one seems to be extremely hard to debug and I frankly do not know how to start. I have not solution mentioned in the previous post as I do not want to rename any of my files and I want to keep my code organised as it is now.
Lastly, to ask a broader question – what is the difference the first and subsequent requests are handled for each of the instances? Is there anything a developer should be aware of?
So what exactly happens – if the appengine’s code is loaded for the first time, I get a blank page. Every subsequent request is fine. I think I have all the required parts of the code there, just in case here are the handlers from app.yaml (also, the app is using python27 as a platform):
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /fb/.*
script: fbhandler.py
- url: /xarpc/.*
script: xmlrpchandler.py
- url: /
script: main.py
- url: .*
script: main.py
The handler in question is the fbhandler.py.
def main():
application = webapp.WSGIApplication([("/fb/", FBHandler)], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
If I examine the appengine logs, I see this for the “blank” request:
2012-05-07 10:43:14.822 /fb/?id=341108955956205 200 2998ms 0kb Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
95.23.245.xx - - [07/May/2012:03:43:14 -0700] "POST /fb/?id=xxx HTTP/1.1" 200 0 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19" "xxx.appspot.com" ms=2999 cpu_ms=563 api_cpu_ms=0 cpm_usd=0.015744 loading_request=1 instance=00c61b117cb0ca2fc61adc3939c4bd034dfa416f
I 2012-05-07 10:43:14.822
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
Compared to this for any good subsequent request:
2012-05-07 10:44:05.479 /fb/?id=341108955956205 200 832ms 0kb Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
95.23.245.xx - - [07/May/2012:03:44:05 -0700] "POST /fb/?id=xxx HTTP/1.1" 200 483 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19" "xxx.appspot.com" ms=832 cpu_ms=1272 api_cpu_ms=1078 cpm_usd=0.035497 instance=00c61b117cb0ca2fc61adc3939c4bd034dfa416f
As you can see, no obvious error messages anywhere.
Update:
Upon advice, I have removed the main() to try to rule out caching, now the handler looks like:
application = webapp.WSGIApplication([("/fb/", FBHandler)], debug=True)
util.run_wsgi_app(application)
Same effect, first load gets blank page and subsequent loads get proper data. What I have noticed that it does not matter if a new code is uploaded or not, if an instance is running and I update the code, it shows properly on the first load. I need to go into instances admin and shut one down to reproduce the error.
Update 2:
I have now tried changing the handlers to the new python27 way:
- url: /fb/.*
script: fbhandler.app
And also corresponding change to the fbhandler
import webapp2
app = webapp2.WSGIApplication([("/fb/", FBHandler)])
Again, same issue. I have also tried removing the debug parameter with no effect.
SOLUTION
I now seem to have found a solution. When I upgraded all of the application handlers to the webapp2 and used the new way of referencing them, it now seems to work without the first load error.