Skip to content

在tornado异步过程中你可以通过异步的等待redis中的key ,当key值存在了过后就返回。这样在爬虫开发时就可以做到解耦合。非常实用

License

Notifications You must be signed in to change notification settings

joobih/tornado_redis_yield

Repository files navigation

Tornado Web Server

Join the chat at https://gitter.im/tornadoweb/tornado

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.

Hello, world

Here is a simple "Hello, world" example web app for Tornado:

import tornado.ioloop
import tornado.web
import tornado.gen

#redis client
from redis_cli import redis_cli


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

    def _call_back(self, value, other_data=None):
        print(value)
        print(other_data)
        self.write(value)
        self.finish()

    @gen.coroutine
    def post(self):
        key = "your redis_key"
        other_data = {
           "key":key
        }
        yield gen.redis_sleep(redis_cli.redis_cli, key, self._call_back, timeout=20, other_data=other_data)


def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

This example does not use any of Tornado's asynchronous features; for that see this simple chat room.

Documentation

Documentation and links to additional resources are available at http://www.tornadoweb.org

About

在tornado异步过程中你可以通过异步的等待redis中的key ,当key值存在了过后就返回。这样在爬虫开发时就可以做到解耦合。非常实用

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages