tornadoweb / tornado

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
http://www.tornadoweb.org/
Apache License 2.0
21.7k stars 5.5k forks source link

Doc/Wiki/Example on how to write non-blocking drivers to support Tornado IOLoop #1414

Open rskumar opened 9 years ago

rskumar commented 9 years ago

Need official extensive doc/wiki with examples on how to write non-blocking networking IO based drivers to interact with external application. That would be nice addon for developers who want to write libraries around Tornado. And it will benefit tornado community.

mivade commented 9 years ago

Can you elaborate on what you mean exactly (maybe a use case you have in mind)? I have made several demo programs for myself to test things out and have thought about combining them into a full-fledged demo.

rskumar commented 9 years ago

What I meant, for example, lets pretend there is no Redis client available which supports Tornado. One that is officially available is blocking. So how should one proceed with analyzing blocking area, and what API to use to make it async (ie.IOStream). How to read chunk when available on socket and when to yield control back to main loop. The best practices and supplements.

v3ss0n commented 9 years ago

@rskumar thats very good proposal.

I believe @ajdavis will be able to enlighten us when he free. He is developer of Motor driver for Tornado and active contributor of Tornado.

His blog usually wrote about how motor is implemented. http://emptysqua.re/blog/

mivade commented 9 years ago

@rskumar I don't have anything so complex as manually connecting to a redis server, but I did make a proof of concept TCP echo client/server here.

Another alternative for tasks suitable for running in the background might be to use the run_on_executor decorator combined with IOLoop.add_callback to notify the IO loop that a result is ready. I think this method works quite well in many cases for applications, though it might be less suitable for a library, in which case coroutines probably make more sense.

rskumar commented 8 years ago

closed by mistake.. Reopening it again