Python Tornado

  • Another client implements a long-polling client hitting /poll waiting for a command to execute.
  • I’d like the commands to essentially be distributed immediately to any long-polling client but held if no client is currently polling.
  • I suspect I need to join the queue, but I can’t seem to find the right time to do that in the code.
  • @tornado.gen.coroutine def getCommand(self): try: # wait for queue item if cannot obtain in timeout raise exception cmd = yield _commandQueue.get( timeout=datetime.timedelta(seconds=_commandPollTimeout) ) return cmd except tornado.gen.
  • I think a queue is the right data structure to use to hold commands waiting for attention.

I’m trying to build a web server to collect “commands” via AJAX and then distribute the commands to clients via long-polling.

@ng_real_ninja: Python Tornado – How to Implement Long-Polling Server to Read from a Queue #angularjs…

I’m trying to build a web server to collect “commands” via AJAX and then distribute the commands to clients via long-polling.

The goal is that someone POSTs some data to /add-command.

Another client implements a long-polling client hitting /poll waiting for a command to execute.

I think a queue is the right data structure to use to hold commands waiting for attention. I’d like the commands to essentially be distributed immediately to any long-polling client but held if no client is currently polling.

Here’s my python script.

and I can’t put or get from it.

I suspect I need to join the queue, but I can’t seem to find the right time to do that in the code.

Python Tornado