Domanda

I'm trying to do some benchmarking of Twisted & Tornado with Mongodb.

I have Twisted and Tornado running with PyMongo (I know this is not async - I am just curious)

I have Tornado running with Asyncmongo. I can not get Twisted running with Asyncmongo.

As an experiment I wrote some simple code to test asyncmongo and the callback is never called. So now I am wondering is asyncmongo tied into Tornado?

import asyncmongo

def main():
  db = asyncmongo.Client(pool_id='mydb', host='localhost', port=27017, maxcached=10, maxconnections=10, dbname='mydb')
  db.houses.find({'price':25, }, callback=_on_response )
  print "query done"

  while True:
    pass

def _on_response(self, response, error):
  print "yay - response"

if __name__ == '__main__':
  main()

"yay - response" - Is never displayed - the callback is not activated.

Is it possible to make the callback fire if you do not use any frameworks? Is it possible to make the callback fire using Twisted's reactor / deferreds? If not how do people usually get Twisted talking to Mongo?

È stato utile?

Altri suggerimenti

From the Asyncmongo README: "AsyncMongo is an asynchronous library for accessing mongo which is built on the tornado ioloop."

So yeah, it's dependant on Tornado. In your example code, it should work if you start the Tornado IOLoop. As far as something to use with Twisted, it looks like @Jean-Paul Calderone's link is your best bet.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top