Thriftpy / thriftpy

Thriftpy has been deprecated, please migrate to https://github.com/Thriftpy/thriftpy2
MIT License
1.15k stars 286 forks source link

Is the Tornado server asynchronous? #305

Closed julioasotodv closed 7 years ago

julioasotodv commented 7 years ago

I am trying to run the example in the docs (in tornado.py):

pingpong = thriftpy.load("pingpong.thrift")
class Dispatcher(object):
    def ping(self):
        return "pong"

server = make_server(pingpong.PingPong, Dispatcher())
server.listen(6000)

This isn't asynchronous Tornado code (since there is no @coroutine decorator in the Dispatcherclass, and it actuallty returns as any simple function).

Can be thriftpy's Tornado server asynchronous in any way?

microdog commented 7 years ago

The Tornado server implemented by thriftpy is asynchronous(using tornado.tcpserver.TCPServer). You can define methods with @gen.coroutine decorator or methods returning Future object.

class Dispatcher(object):
    @gen.coroutine
    def ping(self):
        yield gen.sleep(10)
        raise gen.Return("pong")
julioasotodv commented 7 years ago

Hi,

Yes, you are definetly right. I tried it before, but the problem was that I was trying to send lots of calls in parallel, but from the same client (which isn't async), so I couldn't be able to get benefit from async server side code.

Thank you very much. Great library btw :)