Tornado way to explore https:https://cdn.v2ex.com/navatar/5272/0e00/361_normal.png?m=1579007184 https:https://cdn.v2ex.com/navatar/5272/0e00/361_large.png?m=1579007184 2019-11-14T08:22:33Z Copyright © 2010-2018, V2EX docker 多进程部署 tornado tag:www.v2ex.com,2019-11-14:/t/619557 2019-11-14T07:30:26Z 2019-11-14T08:22:33Z akura member/akura
  • 通常的部署方式是 nginx 负载均衡到多个端口,每个端口绑定开启一个 tornado 服务,通过 supervisor 可以很方便监控服务。
  • 现在想 tornado 多进程用 docker 部署,具体的架构方案是怎么样的?是一个 docker 容器一个进程还是一个 docker 多个进程?
  • ]]>
    Tornado 如何拿到传输的文件流 tag:www.v2ex.com,2019-04-25:/t/558602 2019-04-25T06:58:13Z 2019-04-25T10:09:08Z zhze93 member/zhze93 一个大文件
    我在 client 通过 requests 库来进行传输

    with open(path_file, "rb") as f: res = requests.post(url, data=f, timeout=600) 

    我在 server 端,从 tornado_request 中该如何接收这个文件流并保存下来呢。
    谢谢各位的不吝赐教。

    ]]>
    Tornado 的异步 怎么写的 tag:www.v2ex.com,2019-01-14:/t/527071 2019-01-14T17:43:42Z 2019-02-02T04:04:41Z aoscici2000 member/aoscici2000 看得教程一头雾水, 只能理解那个自带的 http 请求, 看了很久也没看到有比如数据库查询, 文件处理什么的其他例子, 后来去看看其他教程, 实现倒算是勉强实现了, 但感觉也太复杂了吧? ?

    就比如例子中的我假设有个长耗时的任务, 怎么写才会简单点?

     import tornado.ioloop import tornado.web import time import _thread # 模拟耗时任务 def long_work(arg): time.sleep(5) yield arg * 1024 def mycoroutine(func): def wrapper(self): gen = func(self) work_gen = next(gen) def fun(): result = next(work_gen) try: gen.send(result) except StopIteration: pass _thread.start_new_thread(fun, ()) return wrapper class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @mycoroutine def get(self): arg = 10 # 假设请求的参数 result = yield long_work(arg) self.finish(f'<h1>Index {result}</h1>') class SyncHandler(tornado.web.RequestHandler): def get(self): self.write('<h1>SyncHandler</h1>') def make_app(): return tornado.web.Application([ (r'/', IndexHandler), (r'/sync', SyncHandler) ]) if __name__ == '__main__': app = make_app() app.listen(8888) tornado.ioloop.IOLoop.current().start() 
    ]]>
    tornado 下 ckeditor 图片上传问题 tag:www.v2ex.com,2018-12-03:/t/514006 2018-12-03T14:58:02Z 2018-12-03T10:58:02Z aoscici2000 member/aoscici2000 按网上的方法更改了配置后,单纯本地打开 html 文件是显示有图片上传的选项的, 但服务跑起来的方式打开的话, 就没有了, 这是怎么回事??

    ]]>
    Tornado 异步怎么写的? tag:www.v2ex.com,2018-12-02:/t/513504 2018-12-02T04:22:59Z 2018-12-13T17:04:12Z aoscici2000 member/aoscici2000 比如说要等某个耗时操作的结果, 该怎么写?

    网上看了半天例子, 照着做了做, 貌似行不通

    class AsyncTaskHandler(tornado.web.RequestHandler):

    @tornado.web.asynchronous @tornado.gen.coroutine def get(self, *args, **kwargs): resp = yield tornado.gen.Task(self.do_something) self.finish(resp) @tornado.gen.coroutine def do_something(self, *args, **kwargs): time.sleep(10) return {'message': 'OKOK'} 
    ]]>
    tornado 怎么能确保端口挂了 服务也不会停止? tag:www.v2ex.com,2018-11-28:/t/512202 2018-11-28T02:00:59Z 2018-12-20T22:04:34Z kidlfy member/kidlfy 小白 python tornado 也不熟 刚试着用 需要配置两个端口来保证 一个端口挂了另一个会起来 服务不会终止 通过 nginx 要怎么配置? 要哭了 不会做 很尴尬

    ]]>
    Tornado 路由有什么好方法,一个一个写太麻烦了,有没有根据 url 和注解匹配的方法呢 tag:www.v2ex.com,2018-07-03:/t/467856 2018-07-03T09:51:59Z 2018-09-04T23:41:10Z everlasting_188 member/everlasting_188 Tornado V4.5 release tag:www.v2ex.com,2017-03-27:/t/350765 2017-03-27T16:33:42Z 2017-03-27T21:11:59Z mywaiting member/mywaiting
    多了这么一个 routing 的实现,终于有了一个官方点的稍微好看优雅点的方式去组织 Tornado 的 Application 和 Handler 了

    直接看代码吧
    https://github.com/tornadoweb/tornado/blob/master/tornado/routing.py 官方的文档都还没有更新

    Tornado 的代码写得挺优雅的,很适合围观 ]]> pypy 拿到赞助之后出了支持 Python3.5 的版本 tag:www.v2ex.com,2017-03-05:/t/345167 2017-03-05T15:26:08Z 2017-03-17T17:51:04Z lecher member/lecher https://morepypy.blogspot.jp/2017/03/async-http-benchmarks-on-pypy3.html?m=1

    UVloop 新版本也开放了对 tornado 的支持。
    https://github.com/Magicstack/uvloop/issues/35

    看目前网络上面的评测 sanic+uvloop 评测数据遥遥领先。
    如果 pypy 支持 Python3.5 之后, pypy+uvloop+tornado 可以跑出什么样的数据? ]]>
    请教 tornado 文件上传问题 tag:www.v2ex.com,2017-01-05:/t/332360 2017-01-05T03:59:03Z 2017-01-05T05:26:15Z sylvos member/sylvos import tornado.ioloop
    import tornado.web
    import shutil
    import os

    class UploadFileHandler(tornado.web.RequestHandler):
    def get(self):
    self.write('''
    <html>
    <head><title>Upload File</title></head>
    <body>
    <form action='file' enctype="multipart/form-data" method='post'>
    <input type='file' name='file'/><br/>
    <input type='submit' value='submit'/>
    </form>
    </body>
    </html>
    ''')

    def post(self):
    upload_path=os.path.join(os.path.dirname(__file__),'files') #文件的暂存路径
    file_metas=self.request.files['file'] #提取表单中‘ name ’为‘ file ’的文件元数据
    for meta in file_metas:
    filename=meta['filename']
    filepath=os.path.join(upload_path,filename)
    with open(filepath,'wb') as up: #有些文件需要已二进制的形式存储,实际中可以更改
    up.write(meta['body'])
    self.write('finished!')

    app=tornado.web.Application([
    (r'/file',UploadFileHandler),
    ])

    if __name__ == '__main__':
    app.listen(3000)
    tornado.ioloop.IOLoop.instance().start() ]]>
    tornado 做后台服务,如果前端没有用 cookie. tag:www.v2ex.com,2016-12-13:/t/327437 2016-12-13T13:48:27Z 2016-12-13T20:45:27Z feelapi member/feelapi 是不是就不用增加 XSRF 的支持了,毕竟这个还是用来处理 cookie 的。

    ]]>
    tornado 优秀项目推荐 tag:www.v2ex.com,2016-11-18:/t/321411 2016-11-18T02:58:16Z 2016-12-07T19:18:32Z burnex member/burnex 打算好好学习下 tornado ,请大家推荐一些好的 tornado 项目,谢谢

    ]]>
    问一个 tornado 解决阻塞的方案问题? tag:www.v2ex.com,2016-08-20:/t/300584 2016-08-20T02:25:35Z 2016-08-31T21:48:49Z tomhe member/tomhe 手机 app 上传图片->tornado 调用 c++算法库处理->向手机返回结果。
    目前遇到的问题是 c++算法库需要耗时 1 秒左右,这样会把整个 tornado 阻塞住吧?有什么好的异步解决方法或思路吗?
    请问我这个需求可以用协程的方式解决吗?还是用多进程的方式解决? ]]>
    tornaqiniu(基于 tornado 的异步七牛 sdk) tag:www.v2ex.com,2016-08-07:/t/297680 2016-08-07T05:41:53Z 2016-08-07T02:41:53Z whoareyou member/whoareyou 最近在用 Python 开发一个自己的网站,要用到七牛做为网站的 storage ,但是七牛官方 sdk 不支持异步,所以打算自己写一个异步的 sdk 。写出来之后自己用着还可以,所以想给大家分享一下,不喜勿喷。

    python version : >=3.4

    github: https://github.com/free-free/tornaqiniu

    doc: https://github.com/free-free/tornaqiniu

    ]]>
    tornado 并行异步,如何保证在只有部分请求成功后,结果依旧可用。 tag:www.v2ex.com,2016-06-30:/t/289477 2016-06-30T14:46:47Z 2016-06-30T17:43:47Z aiqier member/aiqier tornado 可以使用如下方式并行异步请求。

    @gen.coroutine def get(self): http_client = AsyncHTTPClient() response1, response2 = yield [http_client.fetch(url1), http_client.fetch(url2)] 

    这个时候, 1,2 是同时发送出去的,也就是说使用这种方式,可以让 n 个请求,同时发出去,等他们都返回了再统一返回。

    那么我要如何保证,其中一个请求坏了,其余的结果依旧可用?

    ]]>
    nginx 反向代理 tornado,如何 location 首页u rl? tag:www.v2ex.com,2016-06-29:/t/289074 2016-06-29T03:54:36Z 2016-06-29T09:51:36Z qiu0130 member/qiu0130 nginx反向代理tornado实例,怎么重定向到首页url

    ]]>
    问一个关于 tornado 异常处理的新手问题 tag:www.v2ex.com,2016-06-05:/t/283654 2016-06-05T09:07:42Z 2016-06-14T00:42:57Z mgna17 member/mgna17 刚开始学 tornado ,它的异常处理机制有点弄不明白。

    写了一个测试用的小脚本,期望遇到 404 的时候能够触发我自己声明的 write_error 函数,然而 write_error 并没有生效,输出的是 tornado 默认的 404 页面。

    代码如下:

    #!/bin/env python3.5 #coding:utf-8 import os import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options define("port", default=8000, help="端口", type=int) class BaseHandler(tornado.web.RequestHandler): def write_error(self, stat, **kw): self.write('Func write_error !') class IndexHandler(BaseHandler): def get(self): self.write('hello') handlers = [ (r'/index', IndexHandler), ] settings = { 'template_path': os.path.join(os.path.dirname(__file__), "templates"), 'static_path': os.path.join(os.path.dirname(__file__), 'static'), } if __name__ == '__main__': tornado.options.parse_command_line() app = tornado.web.Application(handlers=handlers, **settings) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) print(options.port) tornado.ioloop.IOLoop.instance().start() 

    然后去 google 了一下,把 BaseHandler 成了这样,但是 404 的时候还是返回了默认的 404 页面:

    class BaseHandler(tornado.web.RequestHandler): def _handle_request_exception(self, e): self.write_error(404) def send_error(self, stat, **kw): self.write_error(404) def write_error(self, stat, **kw): self.write('Func write_error !') 
    ]]>
    tornado 的 coroutine 能和自定义的装饰器一起使用吗?? tag:www.v2ex.com,2016-04-07:/t/269198 2016-04-07T03:45:17Z 2016-04-08T10:58:29Z triThirty member/triThirty 试了下使用 tornado 的 coroutine 和自已定义的一个 decorator 一起使用,但发现不会在 yield 出挂起,而是向上返回。 就是说,如果有多层嵌套的话,在运行到最底层的 yield 处之后,程序不会运行 yield 之后的代码,而是向上返回一个空的 future ,而且上层代码也不会执行 yield 之后的代码而是继续向上返回。 不知道有没有大神能给出一个例子,将 coroutine 和自定义的装饰器一起使用的例子,或者说能指出怎么使用。谢谢

    ]]>
    Tornado 并发数很低,正常么? tag:www.v2ex.com,2016-01-14:/t/250767 2016-01-14T09:47:48Z 2016-01-15T00:41:46Z bluesky139 member/bluesky139 得到的结果是每秒 200 多的并发数,这正常么?

    目前系统是 win7 , CPU 是 E3 1231 ,
    从任务管理器来看,似乎是单线程跑满了(因为进程的 CPU 占用率为 13 )。
    各位用 tornado 的朋友也是同样的结果么? 还是说哪里有坑? ]]>
    阅读 Tornado 源码过程中的一个疑惑,求解答 tag:www.v2ex.com,2016-01-05:/t/248581 2016-01-05T11:50:34Z 2016-01-05T20:07:29Z kidlj member/kidlj 下面是 tornado.httpclient.AsyncHTTPClient类的 fetch()方法的源代码。我没有在里面找到任何"fetch"的动作,它是怎么实现 “ Executes a request, asynchronously returning an HTTPResponse”的?

    完整代码在: https://github.com/tornadoweb/tornado/blob/master/tornado/httpclient.py

    def fetch(self, request, callback=None, raise_error=True, **kwargs): """Executes a request, asynchronously returning an `HTTPResponse`.  The request may be either a string URL or an `HTTPRequest` object.  If it is a string, we construct an `HTTPRequest` using any additional  kwargs: ``HTTPRequest(request, **kwargs)``  This method returns a `.Future` whose result is an  `HTTPResponse`. By default, the ``Future`` will raise an  `HTTPError` if the request returned a non-200 response code  (other errors may also be raised if the server could not be  contacted). Instead, if ``raise_error`` is set to False, the  response will always be returned regardless of the response  code.  If a ``callback`` is given, it will be invoked with the `HTTPResponse`.  In the callback interface, `HTTPError` is not automatically raised.  Instead, you must check the response's ``error`` attribute or  call its `~HTTPResponse.rethrow` method.  """ if self._closed: raise RuntimeError("fetch() called on closed AsyncHTTPClient") if not isinstance(request, HTTPRequest): request = HTTPRequest(url=request, **kwargs) else: if kwargs: raise ValueError("kwargs can't be used if request is an HTTPRequest object") # We may modify this (to add Host, Accept-Encoding, etc), # so make sure we don't modify the caller's object. This is also # where normal dicts get converted to HTTPHeaders objects. request.headers = httputil.HTTPHeaders(request.headers) request = _RequestProxy(request, self.defaults) future = TracebackFuture() if callback is not None: callback = stack_context.wrap(callback) def handle_future(future): exc = future.exception() if isinstance(exc, HTTPError) and exc.response is not None: response = exc.response elif exc is not None: response = HTTPResponse( request, 599, error=exc, request_time=time.time() - request.start_time) else: response = future.result() self.io_loop.add_callback(callback, response) future.add_done_callback(handle_future) def handle_response(response): if raise_error and response.error: future.set_exception(response.error) else: future.set_result(response) self.fetch_impl(request, handle_response) return future def fetch_impl(self, request, callback): raise NotImplementedError() 
    ]]>
    gtornado - tornado 中 pymysql, pymemcache, storm orm 支持库 tag:www.v2ex.com,2016-01-04:/t/248278 2016-01-04T10:05:05Z 2016-01-04T12:02:05Z alex8224 member/alex8224 目前适配了 pymysql, pymemcache 和 storm 的异步化支持.

    更多详细信息可访问: https://github.com/alex8224/gtornado

    ]]>
    Tornado 如何组织中大型项目,你们都是怎么样做的? tag:www.v2ex.com,2015-11-26:/t/239245 2015-11-26T14:24:16Z 2016-08-03T11:58:43Z mywaiting member/mywaiting
    一开始我是这样组织项目的,你没有看错,真心只有这几个文件:

    + project
    | - app.py (基本所有的 handler 都在这里了)
    | - models.py (数据库相关的)
    | + templates
    | + static

    如果要给个参考例子,那 BT 大大的项目来参考吧 https://github.com/finiteloop/socialcookbook 刚刚开始写 tornado 的项目的时候没有那么多的东西,一切都很简洁很美好!

    然后呢,项目越来越多功能了,需要组织的代码越来越多,需要 Seesion ,需要 form 检验等一堆东西,于是重构为这样来组织项目:

    + project
    | + controllers
    | | - acontroller.py
    | | - bcontroller.py
    | | ....
    | + models
    | | - amodel.py
    | | - bmodel.py
    | | ....
    | + templates
    | + forms
    | | - aform.py
    | | - bform.py
    | | ....
    | + helpers
    | | - ahelper.py
    | | - bhelper.py
    | | ....
    | - application.py
    | - urls.py
    | - settings.py

    很直接也很明显,这是拿 Tornado 来做 MVC 这龌龊的事情了,把先前越来越大的 app.py 分开成 controllers 目录, models 目录页一样,增加了 forms 目录和 helpers 目录。 application.py 放置整个 project 的启动、关闭, URL 放在 urls.py , settings 嘛就是配置。

    这样安好运行了好长一段时间,毕竟一个小网站,长成这样已经很对得起我拿的工资了。但是这样的项目结构随着业务的增多感觉越来越力不从心:

    1 、首先业务关联比较多,类似于门户网站那样的 CMS 类型的,这样就无法分出几个项目来应用上面的代码组织了。
    2 、子域名的需求众多,基本一个子域名 a.example.comb.example.com 的代码逻辑是完全不一样的,但是数据库后面的数据却有很多需求重合的。同时原因见 1 ,又无法分出好几个 project 来组织代码

    感觉越来越臃肿的代码结构,越来越多的东西加入到 Tornado 这个大杂烩里面,感觉项目长得越来越像 Django 的项目,但是组织却远不如 Django 的项目组织得好!

    看了一下 Flask 的 Blueprint ,这货貌似在架构大型项目的时候很实用的样子。

    就像这篇文章 https://spacewander.github.io/explore-flask-zh/7-blueprints.html 说到的按照功能(functional)或者分区(divisional)来组织代码。

    按照 分区(divisional) 来组织代码貌似有天生的适合大型的且内部可以松耦合的项目,而类似我上面的 按照功能(functional) 来组织项目就适合组织功能相对内聚的项目。

    按照我这么重构下去,迟早要弄个 Django 出来的感觉。有点后悔当初怎么不直接用 Django 而用上了 Tornado 来自己造各种轮子。

    各位在架构 Tornado 的中大型项目,有什么经验可以分享吗?

    谢谢! ]]>
    tornado 跑不通,小白求帮忙 tag:www.v2ex.com,2015-11-23:/t/238241 2015-11-23T06:16:10Z 2015-11-27T14:23:17Z lydhr member/lydhr Context :
    - tornado 的 helloWorld 教程代码跑不通, localhost:8000 会报错‘未收到数据’

    - 本机并未装 Nginx ,但是 0.0.0.0 打开后会显示 Welcome to nginx!那个欢迎页

    - terminal 中, nginx command not found

    Question :
    - 如何定位自己的 nginx 转到哪里了?
    - tornado 的 helloWorld 哪里不对?

    ]]>
    Tornado 4.3 发布 tag:www.v2ex.com,2015-11-07:/t/234457 2015-11-07T11:53:58Z 2015-11-07T12:50:58Z Gem member/Gem
    In most cases, async def can be used in place of the @gen.coroutine decorator. Inside a function defined with async def, use await instead of yield to wait on an asynchronous operation. Coroutines defined with async/await will be faster than those defined with @gen.coroutine and yield.

    But do not support some features including Callback/Wait or the ability to yield a Twisted Deferred. See the users ’ guide for more.


    http://www.tornadoweb.org/en/stable/releases/v4.3.0.html ]]>
    Tornado 官方怎么不好好维护一个 sql 的异步数据库驱动? tag:www.v2ex.com,2015-11-05:/t/233912 2015-11-05T09:18:38Z 2015-11-06T09:48:26Z Gem member/Gem 关于 tornado 阻塞的问题 tag:www.v2ex.com,2015-10-15:/t/228298 2015-10-15T08:11:43Z 2015-10-20T15:03:46Z dai269619118 member/dai269619118
    def get(self): time.sleep(100) self.write('hello test') 

    如果程序执行的时候中间处理一个需要很多时间,这个时候有一个新的请求
    那么第二个请求需要等待第一个请求执行完才开始执行第二个操作
    接着用 nginx 做了一个负载均衡,开了 3 个 tornado

    upstream to.com{ server 127.0.0.1:8887; server 127.0.0.1:8888; server 127.0.0.1:8889; } 

    可是中间还是有机率切到同一个端口上面,然后又要等待处理,有什么其他处理方面吗?

    ]]>
    tornado 的 mysql 异步驱动性能测试 tag:www.v2ex.com,2015-10-08:/t/226295 2015-10-08T05:50:58Z 2015-10-08T08:18:53Z sujin190 member/sujin190 https://gist.github.com/mosquito/aa20b94fec8b406d9a51 ]]> pypy 之 tornado tag:www.v2ex.com,2015-09-10:/t/219815 2015-09-10T15:24:11Z 2015-09-13T04:16:09Z sujin190 member/sujin190 使用的是官网的示例, i5 四核 8g , mysql 默认配置 ]]> tornado 多个 url tag:www.v2ex.com,2015-08-08:/t/211788 2015-08-08T11:19:47Z 2015-08-08T16:50:49Z xlzd member/xlzd 请问各位, 服务器端用的tornado, 假如几个domain都指向了同一个地址, 应该怎么得到被访问的域名呢?

    ]]>
    RequestHandler 类的 get_current_user() 方法覆写无效 tag:www.v2ex.com,2015-07-27:/t/208772 2015-07-27T15:43:49Z 2015-07-27T20:13:00Z roychan member/roychan 刚刚开始用 Tornado。

    在用户认证时,我覆写了 BaseHandler,以便使用内置的 current_user() 方法与 is_authenticated 修饰器。

    class BaseHandler(tornado.web.RequestHandler): def get_current_user(self): return self.get_secure_cookie('user') 

    在某步中,我加了判断 if self.current_user then xxx,此时即便登录了也无法执行 xxx,如果我把判断写成 if self.get_current_user then xxx,便能成功确认登录,xxx 就执行了。

    请问这可能是什么问题?

    ]]>
    tornado 动态添加 url 的问题 tag:www.v2ex.com,2015-07-17:/t/206354 2015-07-17T05:04:14Z 2015-07-17T07:51:27Z agentwx member/agentwx 最近在看tornado , 看到它的url的处理方式,一般是url(r"/path",sthhandler),突然心里想到能不能直接动态创建这个url,sthhandler一般都是一个类,如果动态创建了一个url, 相应的handler如何动态生成呢? 直接以py文件的形式生成?

    ]]>
    tornado 怎么利用'next'参数进行页面跳转 tag:www.v2ex.com,2015-06-19:/t/199922 2015-06-19T13:38:40Z 2015-06-19T16:33:39Z evolsnow member/evolsnow 在/test的handler添加了@tornado.web.authenticated, 未登录访问时跳转到设置的/login.
    此时网址为"/login?next=%2Ftest", 虽然设置了:self.redirect(self.get_argument("next", "/"))
    但是登录后不返回至"/test"而是到了默认的"/"页面

    网上搜索无果,问题和这大哥一样:
    http://stackoverflow.com/questions/20290020/tornado-next-query-string-url-parameter
    不过该答案并未解决问题, 所以继续来v站求解

    ]]>
    finish() called twice tag:www.v2ex.com,2015-06-17:/t/199311 2015-06-17T09:18:49Z 2015-06-18T02:11:06Z wolegequ member/wolegequ
    有两个返回json接口
    http://example.com/api/user/uid
    http://example.com/api/user/uid/fun

    本打算如此实现 handles
    (r'/api/user/(.*)', user.fun1),
    (r'/api/user/(.*)/fun2', user.fun2 ),

    搞了半天,发现 user.fun1 根本不会调用 ......

    于是乎改为这样

    (r'/api/user/(.*)', user.funs ),


    class funs(BaseController):

    @tornado.web.asynchronous
    def get(self, params):

    if 'fun' in params:
    self.fun2
    else:
    self.fun1

    惊奇的发现 it works !!!(虽然很山寨...)

    重点来了 !!!!

    客户端两个接口先后几乎同时请求

    self.fun1 self.fun2最后都会调用 self.finish(),

    于是乎出现了 finish() called twice - - !

    后来看到有说法@tornado.web.asynchronous 是不可以self.finish()的

    于是乎改为self.fun1 self.fun2最后都调用 self.write(),

    没有 finish() called twice了,但是有一个接口一直没数据返回(单独请求任意一个都正常!)

    醉了醉了.... ]]>
    阿里云 ECS 1CPU 1G 1Mbs 跑 tornado 开多少进程合适? tag:www.v2ex.com,2015-06-03:/t/195754 2015-06-03T04:00:12Z 2015-06-17T09:58:10Z wingyiu member/wingyiu tornado.locale.format_date()的日期汉化问题 tag:www.v2ex.com,2015-05-19:/t/192095 2015-05-19T01:08:12Z 2015-06-03T20:25:01Z tornadoxyz member/tornadoxyz ```
    {{ locale.format_date() }}
    ```
    函数对时间戳进行转化,可是转换后的结果为英文的,例如 2 seconds ago,有没有方法将其汉化为中文呢?粗略的看过tornado.locale模块的源码,可还是一头雾水。望各位朋友不吝赐教。 ]]>
    Tornado 分页问题求解! tag:www.v2ex.com,2015-05-11:/t/190156 2015-05-11T06:12:52Z 2015-05-11T09:37:38Z waynee member/waynee 是参照这个问答进行写的:
    http://stackoverflow.com/questions/15981257/can-tornado-handle-pagination

    路径就是:(r"/",MainHandler)

    逻辑是:
    class MainHandler(BaseHandler):
    def get(self,template_variables = {}):
    news_timeline = self.news_model.get_all_news() #获取所有news
    current_page = int(self.get_argument('page',0)) # 获取当前URL里的page参数
    template_variables["news_timeline"] = news_timeline
    template_variables["current_page"] = current_page
    self.render("index.html",**template_variables)

    HTMl是:
    <body>
    {% for news in news_timeline %}
    <a href = "{{ news["news_link"] }}">{{ news["news_name"] }}</a>
    {% end %}
    {% module Paginator(current_page,5, len(news_timeline)) %}
    </body>

    但是底部的分页链接能够显示出来,可是所有结果都显示在了一个页面,并没有分开显示。现在找不到问题在哪里,是我少些了什么代码吗?

    各位大神,求教!!! ]]>
    Tornado 开发中出错调试如何像 PHP 一样? tag:www.v2ex.com,2015-04-11:/t/183039 2015-04-11T05:45:36Z 2015-04-11T16:11:52Z Emory_M member/Emory_M
    但是Tornado或Python Web开发中如果遇到错误进程退出,都需要修改代码后手动重启进程,体验非常不好

    Node.js可以使用cluster来启动子进程管理, 实现“出错-监控代码修改-重启进程”
    比如: https://github.com/DoubleSpout/ClusterPlus

    Tornado的tornado.autoreload模块似乎只能处理import-time发生的语法错误,并不能持续进入wait监控

    请教一下Tornado下的解决思路 ]]>
    新手完全不懂 tornado.concurrent.Future tag:www.v2ex.com,2015-04-09:/t/182595 2015-04-09T07:33:06Z 2015-04-16T17:13:04Z guoran728 member/guoran728 官方例子:

    from tornado.concurrent import Future

    def async_fetch_future(url):
    http_client = AsyncHTTPClient()
    my_future = Future()
    fetch_future = http_client.fetch(url)
    fetch_future.add_done_callback(
    lambda f: my_future.set_result(f.result()))
    return my_future
    什么协程,异步迷迷糊糊的!

    完全不懂 my_future = Future() 为什么要生成个 Future 对象,最后又返回它!!已经痛苦了几天了!!大神来解救下我吧

    ]]>
    有多少人 有付费学习 Tornado 的意愿,这是一个学习网站。 tag:www.v2ex.com,2015-04-08:/t/182359 2015-04-08T08:52:02Z 2015-06-03T12:26:59Z waynee member/waynee http://learntornado.launchrock.com/ ]]> 请问下 tornado 在 ios app 后台方面有成熟的实现吗? tag:www.v2ex.com,2015-03-11:/t/176237 2015-03-11T16:48:13Z 2015-03-12T05:37:52Z waynee member/waynee 新手求教关于 Tornado + SQLite 的两个问题 tag:www.v2ex.com,2015-02-26:/t/172965 2015-02-26T08:22:28Z 2015-03-15T18:36:12Z invite member/invite 目前的情况是,一个 Tornado 进程, 然后按我的理解,请求来了以后,会自己开线程处理的。 那么问题来了:

    1、多个进程同时读取SQLite,会有锁定么? 网上说多个进程可以同时读写,但说写的时候有锁定,那读的时候,是不是都能立马返回?如果可以立马返回, 那应该可以开多个 Tornado 了吧?

    2、多个线程之间,不能共享句柄么?网上说,多线程之间共享句柄可能存在问题,那多线程查询的话,每次要connect,然后在close么? 怎么样能在 Tornado 里保持SQLite的长连接呢?

    目前的需求是: SQLite 只读,没有写的需求。

    ]]>
    Tornado 4.1 tag:www.v2ex.com,2015-02-22:/t/172185 2015-02-22T10:13:58Z 2015-03-04T19:38:53Z Livid member/Livid http://www.tornadoweb.org/en/stable/releases/v4.1.0.html ]]> 关于优雅地部署 Tornado 新代码的一种方式 tag:www.v2ex.com,2015-02-17:/t/171602 2015-02-17T23:28:33Z 2015-02-18T07:32:00Z Livid member/Livid http://stackoverflow.com/questions/8086885/is-there-a-way-to-deploy-new-code-with-tornado-python-without-restarting-the-ser ]]> Tornado Template 如何获得 Javascript 中的 var 变量? tag:www.v2ex.com,2015-02-12:/t/170521 2015-02-12T09:11:58Z 2015-02-12T12:21:18Z jecvay member/jecvay 我想通过jQuery 发起一个对api的GET请求, 获得一个json格式的list, 然后用 {% for %}控制语句来把json里面的每一个Title给显示出来.

    求教如何在 {% %} 里面调用 jQuery获得的data

    ]]>
    学习 "Introduction to tornado" 提问 tag:www.v2ex.com,2015-01-22:/t/164660 2015-01-22T16:38:25Z 2015-01-22T21:35:25Z pagict member/pagict 具体就是,应该点了 Add to cart 的button 后会隐藏,换为 Remove from cart button, 另外就是 stock left 数要减少吧,但是现在却都没反应。感觉是Javascript 没有正确load,但是小弟又还不懂javascipt。现在猜想是不是书上例子过时了的原因,我的环境是:python 3.4, tornado 4.1.dev1
    有哪位能帮忙看下么?代码倒是照着书上敲的

    目录结构:
    Long Polling/
    |_shopping_cart.py
    |_static/
    |_ _|_scripts/
    |_ _ _|_inventory.js
    |_templates/
    |_ _|_index.html ]]>
    用 Tornado + Mongodb 开发要注意什么? tag:www.v2ex.com,2015-01-20:/t/163815 2015-01-20T05:35:00Z 2015-02-03T13:47:36Z jecvay member/jecvay 我没有开发网站的经验, 只是看过了Python和Tornado那本100多页的入门书.
    现在有个项目是做个管理系统网站, 打算用 Mongodb 数据库.
    而且我对异步什么的没有任何经验,

    请问有什么要注意的?

    ]]>
    用 Tornado 做的网站,大家在写测试的时候,一般都是怎么做的呢? tag:www.v2ex.com,2015-01-18:/t/163238 2015-01-18T09:08:41Z 2015-01-18T13:06:38Z Livid member/Livid 分享本人基于 tornado 开发的应用层框架 tag:www.v2ex.com,2015-01-15:/t/162401 2015-01-15T06:31:38Z 2015-01-14T15:43:04Z mqingyn616 member/mqingyn616 https://github.com/mqingyn/torngas

    Torngas 是基于Tornado的应用开发框架,tornado是一个异步非阻塞的web框架,但是由于其小巧灵活,并没有一个统一,通用的 应用层框架解决方案。Torngas 大量参考和借鉴了Django的设计模式,形成一套基于tornado的Django like应用层开发框架。
    这个框架已经应用在千万级PV的项目里,现在开源出来,希望对大家有用。^ _^

    ]]>
    Nginx 多端口运行 Tornado 如何获取当前端口 tag:www.v2ex.com,2015-01-08:/t/160351 2015-01-08T07:58:39Z 2015-01-08T14:12:54Z jecvay member/jecvay 配置了 Nginx 会将请求分给 8000:8003 四个端口, 我想Tornado建一个页面, 访问这个页面的时候浏览器上能显示出这个页面的请求由哪一个端口获取了, 如何能实现这个功能?

    RequestHandler 貌似没有传进来端口号?

    ]]>
    Tornado 框架如何写 MVC 模式? tag:www.v2ex.com,2014-12-23:/t/156122 2014-12-23T13:06:49Z 2015-01-01T05:34:37Z blueandhack member/blueandhack 之前搜过,没找到一个完整项目,就推荐。 ]]> ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86