关于安装tornado后程序无法运行

按照《python3网络爬虫开发实践》这本书上的方法(用pip)安装好了tornado,然后把书上的helloworld程序敲到python里头运行出现错误,代码和错误如下图所示:
图片说明图片说明
tornado版本为6.0.4,python版本为3.8.3
大佬求教

2个回答

放弃,学其他的web框架,建议直接学django

问题解决了吗?
我也遇到了这个问题

解决了:
是由于 python3.8 asyncio 在 windows 上默认使用 ProactorEventLoop 造成的,而不是之前的 SelectorEventLoop。jupyter 依赖 tornado,而 tornado 在 window 上需要使用 SelectorEventLoop,所以产生这个报错.

请看官方文档:https://www.tornadoweb.org/en/stable/index.html#installation

解决方法是,在 tornado开始执行前添加以下代码,在windows下单独处理:

windows 系统下 tornado 使用 使用 SelectorEventLoop

import platform

if platform.system() == "Windows":
import asyncio

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    参见Python3.8 tornado报错NotImplementedError(转载)_Hank's Techblog-CSDN博客_python tornado notimplementederror https://blog.csdn.net/hank5658/article/details/106870245?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-1
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

在win的VS code上运行tornado项目报路径错误

错误信息: ``` Traceback (most recent call last): File "F:\xvni_hj\tornado_web\lib\site-packages\tornado\web.py", line 1697, in _execute result = method(*self.path_args, **self.path_kwargs) File "F:\xvni_hj\tornado_web\test_web\user\views.py", line 11, in get self.render('index.html') File "F:\xvni_hj\tornado_web\lib\site-packages\tornado\web.py", line 856, in render html = self.render_string(template_name, **kwargs) File "F:\xvni_hj\tornado_web\lib\site-packages\tornado\web.py", line 1002, in render_string t = loader.load(template_name) File "F:\xvni_hj\tornado_web\lib\site-packages\tornado\template.py", line 445, in load self.templates[name] = self._create_template(name) File "F:\xvni_hj\tornado_web\lib\site-packages\tornado\template.py", line 476, in _create_template with open(path, "rb") as f: FileNotFoundError: [Errno 2] No such file or directory: 'F:\\xvni_hj\\tornado_web\\test_web\\user\\templates\\index.html' ``` 文件 : manage.py: ![图片说明](https://img-ask.csdn.net/upload/201904/30/1556590464_701901.png) view.py: ![图片说明](https://img-ask.csdn.net/upload/201904/30/1556590532_168795.png) init.py: ![图片说明](https://img-ask.csdn.net/upload/201904/30/1556590555_515778.png) ![图片说明](https://img-ask.csdn.net/upload/201904/30/1556590579_695180.png) 是只能在Linux下运行吗?

python执行tornado报错

今天装了tornado 写了个测试demo代码如下 ![图片说明](https://img-ask.csdn.net/upload/201804/29/1525007168_382510.png) 在Windows下执行时没有问题的在Linux下执行提示没有zlib模块于是我下载了zlib包执行报错如下 ![图片说明](https://img-ask.csdn.net/upload/201804/29/1525007401_668393.png) 下载了好几个zlib包都报这个错

tornado web.py 重写tornado.web.RequestHandler 的构造函数

我想在url路由中传递参数,但是不会重写tornado.web.RequestHandler的构造函数,求大神指点。 怎么就收路由里面 AppHandler 传递的“abc” 感恩! # coding: utf-8 import datetime, sys, SocketServer,time import tornado.httpserver import tornado.ioloop from tornado.options import define, options import tornado.web import tornado.database import tornado.escape import urlparse import urllib import re reload (sys) sys.setdefaultencoding('utf-8') class Application(tornado.web.Application): def __init__(self): handlers = [ (r"/abc", AppHandler("abc")), ] settings = dict( debug = False, ) tornado.web.Application.__init__(self, handlers, **settings) class AppHandler(tornado.web.RequestHandler): def __init__(self, *args, **kwargs): tornado.web.RequestHandler.__init__( self, *args, **kwargs ) self.action=${接收“abc”} def post(self): try: self.today = datetime.datetime.today() self.did = self.get_argument("did", default = "") except: pass self.set_status(204) self.finish() def get(self): try: pass except Exception, e: raise else: pass finally: pass def main(argv): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application(), xheaders=True) http_server.listen(int(argv[1])) tornado.ioloop.IOLoop.instance().start() print "start listening..." if __name__ == "__main__": main(sys.argv)

python中tornado的使用问题

之前用的是java使用的是tomcat,最近在学习python,在使用tornado的时候有个问题, 一直不知道怎么解决,我在Linux服务器启动tomcat那么我在外网就可以输入ip+端口访问, 并且我在关闭xhell脚本的时候tomcat同样是在运行的,可是tornado我写了一hello world的demo 启动以后外网也是可以访问的但是当我关闭xhsell的时候tornado就关闭了,是需要配置什么东西吗? 代码如下: ![图片说明](https://img-ask.csdn.net/upload/201805/07/1525700422_216465.png)

python3.8+tornado6 线程池ThreadPoolExecutor数量设置无效问题

![图片说明](https://img-ask.csdn.net/upload/202003/06/1583478553_982699.png) 如图所示: 将ThreadPoolExecutor线程池的数量设置为1后,还是不会阻塞,两个请求可以同时运行,经测试,无论ThreadPoolExecutor里面的数量填多少,最后都是10个,不清楚哪里出了问题,但是,如果将线程池脱离tornado,直接在控制台中运行,是可以控制其数量的,有没有人遇到过这种问题??

tornado怎么打开命令行终端??

tornado vxworks5.5 怎么打开命令行终端??我想编译一份源码,借助他的cmd控制行,我自己没找到,请问有人知道吗?

tornado队列put完后,get方法没有触发

tornado.queues.Queue的队列里put了新的数据,但是没有触发,有人知道为啥吗? @gen.coroutine def sendMsg(self): while 1: logger.info('sendMsg moniter start!') data = yield self.msg_que.get() logger.info('sendMsg moniter rev:%s'%data) try: self.handle_msg(data) except Exception as e: logger.info('sendMsg error:%s' % e) finally: self.msg_que.task_done() 我再rev里加了个断点,发现self.msg_que里是有数据的

tornado 请求相同url阻塞

先贴代码 ``` import time from tornado.gen import coroutine from tornado.httpclient import AsyncHTTPClient from tornado.ioloop import IOLoop from tornado.web import Application, RequestHandler class MainHandler(RequestHandler): @coroutine def get(self): client = AsyncHTTPClient() urls = ['http://www.baidu.com'] * 20 start = time.time() yield [client.fetch(url) for url in urls] print(time.time() - start) def make_app(): return Application([(r"/", MainHandler), ]) if __name__ == "__main__": app = make_app() app.listen(8888) IOLoop.current().start() ``` 我通过浏览器访问http://localhost:8888/ ,get方法中请求了相同的链接50次,但是发现所花费的时间是所有请求耗时的总和。百度了发现请求相同的链接会阻塞,但是没找到解决方案。 试了在链接后面加上不同的参数,结果还是阻塞的。 请问各位大佬有解决方案吗?

python tornado异步接口如何写?

为什么我跟别人写的一样,别人的视频里就有异步效果,而我的还是同步效果 ![图片说明](https://img-ask.csdn.net/upload/202002/06/1580996346_773904.png) 代码如下 ``` import tornado.web import time import tornado.gen import tornado.concurrent from concurrent.futures import ThreadPoolExecutor class IndexHandler(tornado.web.RequestHandler): executor=ThreadPoolExecutor(900) @tornado.concurrent.run_on_executor def db_querys(self): print("开始等待") time.sleep(10) print("等待结束") print("------------------------------------") self.write("ok") @tornado.gen.coroutine def get(self): print("开始执行了") yield self.db_querys() print("执行结束") ```

tornado框架,前端css资源,浏览器无法缓存的问题

公司的云平台上线,网页点击特别卡,打开谷歌的F12,查看network, 发现好几个三四百K大的css文件,加载耗时一两秒,共耗时6s左右。 然后决定将静态资源缓存在浏览器,二次加载时就不用去服务器请求资源。 网上查了好多资料,描述基本一致,说是tornado框架在页面上使用模板语言, 一个 static_url 函数,即引用css资源时写为:<link rel="stylesheet" href="{{static_url('aaa.css')}}">, 这样可以实现css缓存。 可事实却并非如此,实验发现,部分大小较小,比如几B的css文件可以次次都去读缓存, 但是那几个较大的css文件不是每次都去读缓存,大多数时间还是去请求服务器资源的。 ![图中显示的资源多次刷新没有读取缓存](https://img-ask.csdn.net/upload/201711/13/1510542676_68751.png) ,而且奇葩的是,像js,img这样的资源不论有多大都会缓存。这个问题一直没有解决就暂时搁置了。 然后去申请云平台的数字证书,买完后,将证书安装,打开首页,地址栏由原来的不安全显示为安全。 然后又随手刷新了几次页面,突然发现,页面加载速度变快了,打开F12发现,所有的css文件都去读缓存了 ![图中可见from cache字样,是读取缓存的](https://img-ask.csdn.net/upload/201711/13/1510542694_543678.png) ,难道缓存与否跟认证的整数有关系么?接着把安装好的证书拿掉,换回原来的非认证的证书,果然浏览器又不缓存了。 所以在这里请各位解答我的疑惑, tornado + bootstrap, 前端浏览器如何实现css静态资源的缓存? 浏览器的缓存是否与CA认证的证书有关?

python tornado编程时页面如何连续输出

tornado写服务时,某个请求耗时较长,并且有有持续的输出,在get()中的write()函数只在get()函数执行完之后才会在页面打印相应的内容,如何实现将执行过程中的输出实时的打印出页面? ``` class TestHandler(tornado.web.RequestHandler): def get(self): import time for i in range(10): self.write('this is ime test') time.sleep(1) ``` 我希望的结果是页面上也是每隔一秒打印一次,可实际结果是等10s后页面会一次性显示所有的字符串,求问怎么解决该问题?

tornado登陆跳转问题 用ajax提交post请求

用ajax提交post请求后通过验证服务器返回跳转地址,然后又莫名出现了get请求跳回login页面。服务器log如下: ``` [I 170208 15:58:10 web:1971] 200 GET /login (::1) 2.00ms test1 123456 [I 170208 15:58:19 web:1971] 302 POST /login (::1) 3.00ms [I 170208 15:58:19 web:1971] 304 GET / (::1) 2.00ms [I 170208 15:58:19 web:1971] 200 GET /login?_xsrf=2%7Ceaa8943a%7C09432d5ffa3cd4bc80fe8232a2f5e89e%7C1486526704 (::1) 2.00ms ``` 很好奇?_xsrf=27C09432d5ffa3cd4bc80fe8232a2f5e89e%7C148如何添加进去的 index.py ``` #!/usr/bin/env Python # coding=utf-8 import tornado.escape import methods.db as mrd from handlers.base import BaseHandler class LoginHandler(BaseHandler): def get(self): self.render('login.html') def post(self): username = self.get_argument("username") password = self.get_argument("password") print(username,password) user_infos = mrd.select_table(table="users",column="*",condition="username",value=username) if user_infos: db_pwd = user_infos[0][2] if db_pwd == password: self.set_current_user(username) self.redirect("/") else: self.write("2") else: self.write("1") def set_current_user(self, user): print(user) if user: self.set_secure_cookie('user', tornado.escape.json_encode(user))#注意这里使用了 tornado.escape.json_encode() 方法 #print(tornado.escape.json_decode(self.current_user)) else: self.clear_cookie("user") class WelcomeHandler(BaseHandler): @tornado.web.authenticated def get(self): username = tornado.escape.json_decode(self.current_user) self.render('index.html', user=username) print(username) ``` login.html ``` <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="{{static_url("css/bootstrap.min.css")}}" /> <style> body{ padding: 70px 0; } .pos_m{ margin-top: 10%; margin-bottom: 10%; } </style> </head> <body> <div class="container pos_m"> <div class="row justify-content-center"> <div class="col-lg-3 col-md-5 col-sm-8 "> <form class="form-signin"> {% module xsrf_form_html() %} <h2 class="form-signin-heading">Please sign in</h2> <div class="form-group"> <label for="InputUserName" class="sr-only">username</label> <input type="text" class="form-control form-control-danger" placeholder="Username" id="username"> <label for="InputPassword" class="sr-only">password</label> <input type="password" class="form-control" placeholder="Password" id="password"> </div> <div class="checkbox"> <label> <input type="checkbox"> Remember me </label> </div> <button type="submit" class="btn btn-primary btn-block" id="login">Submit</button> </form> </div> </div> </div> </body> </html> ``` script.js ``` function getCookie(name){ var x = document.cookie.match("\\b" + name + "=([^;]*)\\b"); return x ? x[1]:undefined; } $(document).ready(function(){ $("#login").click(function(){ var user = $("#username").val(); var pwd = $("#password").val(); var pd = {"username":user, "password":pwd, "_xsrf":getCookie("_xsrf")}; $.ajax({ type:"post", url:"/login", data:pd, cache:false, success:function(data){ alert(data); } }); }); }); ``` 菜鸟入门 求大神指教,调试一天了,实在不知道问题在哪里。

python tornado4.0.2 异步问题

用tornado时,每个请求sleep5秒,异步的方式,但是从浏览器测试没有出现异步的效果,哪位大侠知道呢 class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @tornado.gen.coroutine def get(self): print("begin") #yield tornado.gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 5) yield gen.Task(IOLoop.instance().add_timeout, IOLoop.instance().time() + 5) ¦ print("after") ¦ greeting = self.get_argument('greeting', 'Hello') ¦ self.write(greeting + ', friendly user!') ¦ self.finish() if __name__ == "__main__": tornado.options.parse_command_line() app = tornado.web.Application(handlers=[(r"/", IndexHandler)]) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()

Tornado 这个程序的设计

Problem Description Professor Jonathan is a well-known Canadian physicist and meteorologist. People who know him well call him “Wind Chaser”. It is not only because of his outstanding tornado research which is the most influential in the academic community, but also because of his courageous act in collecting real data of tornados. Actually he has been leading his team chasing tornado by cars equipped with advanced instruments hundreds of times. In summer, tornado often occurs in the place where Professor Jonathan lives. After several years of research, Wind Chaser found many formation rules and moving patterns of tornados. In the satellite image, a tornado is a circle with radius of several meters to several kilometers. And its center moves between two locations in a straight line, back and forth at a fixed speed. After observing a tornado’s movement, Wind Chaser will pick a highway, which is also a straight line, and chase the tornado along the highway at the maximum speed of his car. The smallest distance between the Wind Chaser and the center of the tornado during the whole wind chasing process, is called “observation distance”. Observation distance is critical for the research activity. If it is too short, Wind Chaser may get killed; and if it is too far, Wind Chaser can’t observe the tornado well. After many times of risk on lives and upset miss, Wind Chaser turns to you, one of his most brilliant students, for help. The only thing he wants to know is the forthcoming wind chasing will be dangerous, successful or just a miss. Input Input contains multiple test cases. Each test case consists of three lines which are in the following format. xw1 yw1 xw2 yw2 vw xt1 yt1 xt2 yt2 vt dl du In the first line, (xw1, yw1) means the start position of Wind Chaser; (xw2, yw2) is another position in the highway which Wind Chaser will definitely pass through; and vw is the speed of the car. Wind chaser will drive to the end of the world along that infinite long highway. In the second line, (xt1, yt1) is the start position of tornado; (xt2, yt2) is the turn-around position and vt is the tornado’s speed. In other words, the tornado’s center moves back and forth between (xt1, yt1) and (xt2, yt2) at speed vt . The third line shows that if the observation distance is smaller than dl , it will be very dangerous; and if the observation distance is larger than du, it will be a miss; otherwise it will lead to a perfect observation. All numbers in the input are floating numbers. -2000000000 <= xw1, yw1, xw2, yw2, xt1, yt1, xt2, yt2 <= 2000000000 1 <= vw, vt <= 20000 0 <= dl, du <= 2000000 Note: 1. It’s guaranteed that the observation distance won’t be very close to dl or du during the whole wind chasing process. There will be at least 10-5 of difference. 2. Wind Chaser and the tornado start to move at the same time from their start position. Output For each test case output one line contains one word “Dangerous”, “Perfect” or “Miss” which describes the prediction of the observation. Sample Input 0 0 1 0 2 10 -5 12 7 4 1.3 2.7 0 0 1 0 2 10 -5 12 7 1 0.3 0.4 Sample Output Dangerous Perfect

求tornado项目教程+源码

最近公司做项目要用tornado,刚学了三天python,马上就要用tornado了,发现相关书籍和教程太少了。各位大佬帮帮忙,谢谢了!

python+tornado长连接如何实现推送消息实时更新到界面上

看过tornado的教程,里面有长连接实时更新数据到界面,但都是点击按钮后发送post请求,在post请求中遍历了回调函数,使数据实时更新。但是我现在数据是通过python写了一个回调函数给C调用,C端接收数据后调用我的回调函数解析,C调用我的回调函数解析后我需要将数据推送到界面上,我改如何实现,现在在我的python回调函数中遍历界面显示的回调函数报如下的错![图片说明](https://img-ask.csdn.net/upload/201908/09/1565335531_550708.png)

请教一个通过tornado,实现udp和http同时通信的问题

我需要用tornado来做一个手机远程控制家电的程序,手机用http请求,与底下家电通信用udp,同时监听两种协议的端口呢?

Pyinstaller打包的exe文件在其他电脑无法正常运行

Python3.7.7 版本 在打包的电脑上,运行正常,且卸载需要的第三方库后,仍能正常运行 使用其他电脑(平台相同),就会报错,从报错信息来看,是第三库没能正确识别并有 Import Error:DLL load faied:The specified module could not be found. pywin32 pyinstaller均是最新版本

python中使用tornado 中post get 请求报错500

我用tornado写了两个接口,第一个没有问题,然后我吧第一个复制到第二个文件里就报错了 第一个接口代码如下: ``` import tornado from wtforms_tornado import Form import sys from app.view.view_xxm.mysqlfuntion import selectnav class hello(tornado.web.RequestHandler): def get(self): self.render("hello.html") class ajaxtest(tornado.web.RequestHandler): def set_default_headers(self): print("setting headers!!!") self.set_header("Access-Control-Allow-Origin", "*") self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') def get(self): import json type1 = self.get_argument("type") print(type1) data = [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}] data1 = selectnav(type1) res=dict() res=[ dict( id=k.id, imgurl=k.imgurl, link=k.link, title=k.title, type=k.type, addtime=k.addtime )for k in data1 ] print(res) json = json.dumps(res).encode("utf-8").decode('unicode_escape') self.write(json) # data="你好我是刘德华天涯何处无芳草" # # data.encode("utf-8") # # print("get") # # self.write(data) ``` 第二个接口代码如下 ``` import tornado from wtforms_tornado import Form import sys from app.view.view_xxm.mysqlfuntion import selectnav class hello(tornado.web.RequestHandler): def get(self): self.render("hello.html") class selectnav(tornado.web.RequestHandler): def set_default_headers(self): print("setting headers!!!") self.set_header("Access-Control-Allow-Origin", "*") self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') def post(self): import json type1 = self.get_argument("type") print(type1) data = [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}] data1 = selectnav(type1) res=dict() res=[ dict( id=k.id, imgurl=k.imgurl, link=k.link, title=k.title, type=k.type, addtime=k.addtime )for k in data1 ] print(res) json = json.dumps(res).encode("utf-8").decode('unicode_escape') self.write(json) # data="你好我是刘德华天涯何处无芳草" # # data.encode("utf-8") # # print("get") # # self.write(data) ``` 报错信息如下: ![图片说明](https://img-ask.csdn.net/upload/201805/17/1526566563_860787.png) 完整代码下载地址 [下载地址](http://test.x-x-mo.com/xxmBackstage.zip "xxmBackstage.zip") 接口路由是ajax和xxm这两个

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c# 按行txt c#怎么扫条形码 c#打包html c# 实现刷新数据 c# 两个自定义控件重叠 c#浮点类型计算 c#.net 中文乱码 c# 时间排序 c# 必备书籍 c#异步网络通信
立即提问