I want to ask - does some async Cassandra lib for tornado exists or
not? How can I communicate asynchronously with Cassandra from Tornado?
Or maybe Cassandra will not bring any difference and I should use
async lib for MongoDB (and MongoDB too)?
import tornado.platform.twisted
from telephus.pool import CassandraClusterPool
from twisted.internet import reactor
tornado.platform.twisted.install()
from twisted.internet import reactor
pool = CassandraClusterPool([HOST], keyspace='XXXX',
reactor=reactor)
pool.startService()
reactor.run() # this calls
tornado.ioloop.IOLoop.instance().start()
The one big note is that you need a git checked out version of Tornado,
since there was one bug fix we had to make to keep twisted happy.
--koblas
import sys
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.escape
import tornado.platform.twisted
from telephus.pool import CassandraClusterPool
from twisted.internet import reactor
class PlaceHandler(tornado.web.RequestHandler):
def get(self, id):
self.write('GET detected')
def post(self):
login = self.get_argument("login")
password = self.get_argument("pass")
if login == "dizpers" and password == "test":
self.write(tornado.escape.json_encode({"authed":"y"}))
else:
self.write(tornado.escape.json_encode({"authed":"n"}))
application = tornado.web.Application([
(r"/auth", PlaceHandler)
])
if __name__ == "__main__":
#tornado.platform.twisted.install() <= if don't comment this, i
receive ReactorAlreadyInstalledError
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(sys.argv[1])
pool = CassandraClusterPool(['localhost'], keyspace='Test',
reactor=reactor)
pool.startService()
reactor.run()
tornado.ioloop.IOLoop.instance().start()
You wrote that reactor.run() starts IOLoop too, but if don't use
tornado.ioloop.IOLoop.instance().start() in last line - script don't
handle POST or GET requests
On 22 ноя, 19:49, Joe Bowman <bowman.jos...@gmail.com> wrote:
> After writing the asynchronous sessions library using mongodb and
> asyncmongo, I'd honestly suggest you try just using
> Cassandra synchronously first as well. Cassandra is really fast and you may
> find that it's not worth the code complexity to make it asynchronous.
>
> That said, there's also CQL for Cassandra now, here's a link to the python
> package for it -http://pypi.python.org/pypi/cql/1.0.5