Comments (6)
接上文、主方法里面if name == ‘main’:需改为if name == 'main':
orm.py里面所有的yield from我都改成了await,测试代码可运行,但不知道会不会有隐性bug、、
from awesome-python3-webapp.
python 版本3.6以上才能在async里面使用yield
参考:https://stackoverflow.com/questions/47376408/why-cant-i-yield-from-inside-an-async-function?noredirect=1&lq=1
3.6以后async里面也不能用yield from,貌似是因为编译起来太费时了。
参考:https://stackoverflow.com/questions/47376408/why-cant-i-yield-from-inside-an-async-function?noredirect=1&lq=1
关于test.py原网页有学员在评论了提供了测试成功的代码
import orm
from models import User,Blog,Comment
import asyncio
async def test(loop):
await orm.create_pool(loop,user='root',password='password',db ='python')
u = User(name='Test',email ='[email protected]',passwd='123456',image='about.blank')
await u.save()
if name == 'main':
loop = asyncio.get_event_loop()
loop.run_until_complete(test(loop))
print('Test finished.')
loop.close()
但是orm.py里面也有async里面使用yield from的写法,这个我在尝试解决、、等我测试好了分享
from awesome-python3-webapp.
前面的name是前后加双下划线、github给我自动转换了、
from awesome-python3-webapp.
main前后也要双下划线、、
from awesome-python3-webapp.
/Users/jiuxiaxixi/.conda/envs/webapp/bin/python /Users/jiuxiaxixi/PycharmProjects/webapp/www/testModel.py
Test finished.
Exception ignored in: <bound method Connection.del of <aiomysql.connection.Connection object at 0x108d77c88>>
Traceback (most recent call last):
File "/Users/jiuxiaxixi/.conda/envs/webapp/lib/python3.6/site-packages/aiomysql/connection.py", line 1057, in del
File "/Users/jiuxiaxixi/.conda/envs/webapp/lib/python3.6/site-packages/aiomysql/connection.py", line 300, in close
File "/Users/jiuxiaxixi/.conda/envs/webapp/lib/python3.6/asyncio/selector_events.py", line 621, in close
File "/Users/jiuxiaxixi/.conda/envs/webapp/lib/python3.6/asyncio/base_events.py", line 580, in call_soon
File "/Users/jiuxiaxixi/.conda/envs/webapp/lib/python3.6/asyncio/base_events.py", line 366, in _check_closed
RuntimeError: Event loop is closed
运行你说的代码出现如下错误
from awesome-python3-webapp.
发现代码没有关闭 数据库的连接 已经解决
from awesome-python3-webapp.
Related Issues (20)
- mac 上执行fab build 出现异常,初学者不太懂,在网上找了下也没有看到类似的,但是在我的Windows上是可以的 HOT 1
- day10: 点击注册后页面出现:网络好像出问题了 (HTTP 500) HOT 1
- Page少传了index参数
- Lack of TABLE awesome.blogs 缺少table awesome.blogs
- TypeError: __init__() takes 1 positional argument but 2 were given
- orm.py 模块excute函数里面affected变量可能存在referenced before assignment. HOT 3
- day05 coroweb.py中web.HTTPBadRequest('Missing Content-Type.')缺少text参数 HOT 1
- day4 最后test的时候出现awesome.user doesnt exist的报错 HOT 3
- Day07 jinja2模版文件TemplateSyntaxError: unexpected '}' HOT 1
- Day3 orm.py Undefined variable 'StandardError' HOT 2
- gg
- ga
- a
- 关于注册功能 HOT 5
- post 的url携带参数处理
- where is tech-video for the webapp?
- Kn HOT 1
- Can someone create a translated readme? HOT 1
- Add an Expo e-commerce complete project HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome-python3-webapp.