tau161
asked on
Thread starts, but control never moves past start() call.
Greetings all,
I am working on a simple google AppEngine app that uses python threads. The POST method for MainHandler is where the problem is. The Post method here is supposed to start a thread (which does background downloading) as the last thing before it returns (sending the HTML response). The problem is that although the threads starts just fine, program control doesn't move beyond the start() statement - and so doesn't leave the POST method until the thread is actually finished. It is as though the join() method was called on this thread. I have also tried using a Timer in case the thread was simply hogging cpu time so that control couldn't get to the 'return' fast enough. But that wasn't it either.
The threading code was working fine before I converted it to a Google App. Threads would start and control would move on to the next commands every time. Is there something specific about server-side google apps, or is there some workaround with more advanced threading?...
I am working on a simple google AppEngine app that uses python threads. The POST method for MainHandler is where the problem is. The Post method here is supposed to start a thread (which does background downloading) as the last thing before it returns (sending the HTML response). The problem is that although the threads starts just fine, program control doesn't move beyond the start() statement - and so doesn't leave the POST method until the thread is actually finished. It is as though the join() method was called on this thread. I have also tried using a Timer in case the thread was simply hogging cpu time so that control couldn't get to the 'return' fast enough. But that wasn't it either.
The threading code was working fine before I converted it to a Google App. Threads would start and control would move on to the next commands every time. Is there something specific about server-side google apps, or is there some workaround with more advanced threading?...
# from class MainHandler(webapp.RequestHandler):
def post(self):
logging.info( "ENTERED 'POST' METHOD" )
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(HTMLHeader())
self.response.out.write( "<p>-- PROCESSING --</p>" )
self.response.out.write(HTMLFooter())
logging.info( "LEAVING 'POST' METHOD" )
myPersonDownloader.start()
#Timer(3.0, myPersonDownloader.start ).start()
return # Doesn't get here until thread is finished.
----------
...
----------
def main():
application = webapp.WSGIApplication(
[('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers