I’m developing a GAE application using python and i want it to serve requests concurrently. For this effect I have set threadsafe to true.
I have defined two methods in my request handler:
POST – which enqueues a pull task to execute asynchronously, which will later itself enqueue a pull task as a response:
def post(self):
message = self.request.body
taskqueue.add(url='/process', params={'message': message}) #this task will enqueue a pull task as a response
GET – polls the pull task queue for the response until there’s one available (I know I should find a way to improve that loop, but I’m just trying it out):
def get(self):
(...)
tasks = queue.lease_tasks_by_tag(1, 100, tag)
while tasks.__len__() == 0:
time.sleep(1)
tasks = queue.lease_tasks_by_tag(1, 100, tag)
The client application calls POST and then GET. I put a breakpoint on the task that is enqueued by the POST method, but it’s never called while there’s a request handler stuck in the loop.
I thought the application was supposed to have several threads serve the requests, so how come it is not executing the push request handler concurrently?
I’d appreciate any help with this.
I suspect that you are seeing the behaviour as described in your question from the development server, which cannot serve more than one request at a time. So when you put your breakpoint in the POST method, the dev server is effectively paused. To see this behaviour as intended, upload to App Engine.
Further, instead of polling using a GET HTTP request, try using App Engines Channel API. Using this, you can push a response back to the client directly from your task queue handler to notify that the process is complete (or whatever).