Link to home
Start Free TrialLog in
Avatar of tau161
tau161Flag for United States of America

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?...

# 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()

Open in new window

Avatar of tau161
tau161
Flag of United States of America image

ASKER

I found the unfortunate answer that I was looking for here.  Google App Engine does not support threading.  I wrote a fully working set of threaded base code which is now useless.  I have rewritten it from the ground up using Tasks, TaskQueues, and the Datastore, but it's just not the same. It feels like a hack job.  

Cheers
ASKER CERTIFIED SOLUTION
Avatar of EE_AutoDeleter
EE_AutoDeleter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial