tornado
共 5 篇文章
Tornado ioloop源码简析
#!/usr/bin/env python #-*-encoding:utf-8-*- from tornado import httpserver from tornado import ioloop def handle_request(request): message = "You requested %s\n" % request.uri request.write("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % ( len(message), message)) request.finish() http_server = …
Tornado httpserver 源码简析
整个流程就是创建一个[b]socket[/b] [list] [*]socket.socket [*]socket.bind [*]socket.listen [*]socket.accept [/list] 一些值得注意的地方: [list] [*]sock.setblocking [*]set_close_exec(sock.fileno()) [/list] [code="python"] #!/usr/bin/env python #-*-encoding:utf-8-*- from tornado import httpserver from tornado import iolo…
2013-03-17 01:49 · python · tornado · Socket · Socket · Python · Tornado
Tornado gen简介
**Contains: ** 1、iterator 2、generator 3、yield expressions 4、tornado.gen **一、迭代器 ** Python supports a concept of iteration over containers. This is implemented using two distinct methods; these are used to allow user-defined classes to support iteration. Sequences, described below in more detail, al…
Tornado web简介
[b]Thread-safety notes: [/b] [quote] In general, methods on RequestHandler and elsewhere in tornado are not thread-safe. In particular, methods such as write(), finish(), and flush() must only be called from the main thread. If you use multiple threads it is important to use IOLoop.add_callback to …
2013-03-10 00:25 · python · tornado · Python · Web · Tornado
Tornado中的单例模式(Singleton)
**单例模式也是设计模式一书中介绍的23中设计模式之一。 **Questions: 1、@classmethod和@staticmethod 的用法与区别? 2、Singleton的实现 3、Singleton什么时候适合使用? 问题1、 A staticmethod is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument. It is basicall…
2013-03-08 23:56 · python · tornado · 设计模式 · 设计模式 · Python · Tornado