Git Product home page Git Product logo

Comments (6)

Qing1998 avatar Qing1998 commented on May 24, 2024 1

接上文、主方法里面if name == ‘main’:需改为if name == 'main':
orm.py里面所有的yield from我都改成了await,测试代码可运行,但不知道会不会有隐性bug、、

from awesome-python3-webapp.

Qing1998 avatar Qing1998 commented on May 24, 2024

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.

Qing1998 avatar Qing1998 commented on May 24, 2024

前面的name是前后加双下划线、github给我自动转换了、

from awesome-python3-webapp.

Qing1998 avatar Qing1998 commented on May 24, 2024

main前后也要双下划线、、

from awesome-python3-webapp.

jiuxiaxixi avatar jiuxiaxixi commented on May 24, 2024

/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.

jiuxiaxixi avatar jiuxiaxixi commented on May 24, 2024

发现代码没有关闭 数据库的连接 已经解决

from awesome-python3-webapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.