irqed
irqed

Reputation: 649

Gevent + tornado.httpserver.HTTPServer

is there any way to run tornado.httpserver.HTTPServer inside gevent?

I'm writing a simple proxy server for a big file uploads, the idea is simple - it monitors a free space on bunch of the servers(no problems with that so far), and should route PUT requests to one of WebDAV servers. For efficiency I want to stream it chunk by chunk and couldn't come up with solution based on pywsgi from gevent.

settings = setup()
log.info('Listening on %s:%d' % (settings.host, settings.port))

# server for request routing
server = WSGIServer((settings.host, settings.port), app)

# separate greenlet to periodically get info about cluster free space
monitor = gevent.spawn(storage_monitor, settings.timeout)

# setup a proper signals to stop server and monitor greenlet
gevent.signal(signal.SIGTERM, monitor.kill)
gevent.signal(signal.SIGINT, monitor.kill)
gevent.signal(signal.SIGQUIT, monitor.kill)

gevent.signal(signal.SIGTERM, server.stop)
gevent.signal(signal.SIGINT, server.stop)
gevent.signal(signal.SIGQUIT, server.stop)

# start the server
server.start()
gevent.wait()

Maybe I just don't understand something in general? Since gevent docs didn't update to 1.0 yet it's quite a task:)

And maybe it's better to user gevent's StreamServer + custom protocol?

Upvotes: 0

Views: 516

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22134

It's possible to combine Tornado and greenlet-style concurrency (see e.g. Motor, or the top answer on this question), but it's complicated and serves mainly as a bridge between the synchronous and asynchronous worlds. In a new project I would urge you to pick one style and stick with it rather than combine multiple complicated frameworks.

Secondly, Tornado's HTTPServer doesn't currently (version 3.1) support streaming requests, so it doesn't give you what you want either. I think Twisted does, but again I would recommend picking either Twisted or gevent rather than trying to combine them.

Upvotes: 2

Related Questions