1.复习内容
2.灵感代办
3.学习内容
-
django url传参
- url(‘’,args())
-
Django: Unable to get repr for 解决方案
- 重写__str__
-
javasxript跨文件访问
-
python 多个异常嵌套
-
python中 from的两个
- yield from 生成器
- raise TypeError from Class
-
mysql模糊查询
- like 关键字,效率很低,多字段查询也不方便
-
全文检索
- 指定的字段中(多个字段),检索
-
搜索引擎原理
- 搜索引擎会在数据库中对数据进行预处理
- 建立一份索引结构数据,方便查找数据(类似字典的检索)
- 根据索引,查找到数据,找到数据的真实位置
-
Elasticsearch介绍
- 作用:
- 实现全文检索
-
Haystack
-
Post上传的几种方式
-
Django timezone
-
datetime
- p 是prase 解析
- f 是 from 读取
-
asyncio 使用
-
为什么要讲?
- 异步非阻塞,asyncio
- tornado,fastapi django 3.x asgi aiohttp 高性能 往异步发展
-
1.协程
- 介绍协程
- 协程不是计算机中真实存在的,程序员创造的
- 微线程,上下文切换的技术
- 用一个线程在代码之间游走运行,在函数之间进行切换
- 实现协程的模块
-
greenlet早期模块
-
from greenlet import greenlet
def fun1():
print(1)
gr2.swich()
print(2)
gr2.swich()
def fun2():
print(3)
gr1.swich()
print(4)
gr1.swich()
gr1 = greenlet(func1)
gr2 = greenlet(func2)
gr1.switch()
-
greenevent 基于greetlet
- 补充
-
yield 可以伪造成一个协程
-
def func1():
yield 1
yield from func2()
yield 2
def func2():
yield 3
yield from fun1()
yield 4
f1 = func1()
fro item in f1:
print(f1)
-
asyncio 通过装饰器(py3.4)
- 优势:遇到io阻塞,自动切换
-
# 比如下载图片是时候可以自动切换
import asyncio
@asyncio.coroutine
def func1():
print(1)
# 网络io请求
yield from asyncio.sleep(2)
print(2)
@asycnio.coroutine
def func2():
print(3)
# 网络io请求
yield from asyncio.sleep(2)
print(4)
tasks = [
asyncio.ensure_future(func1()),
asyncio.ensure_future(func2()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait())
-
async、await 关键字 (py3.5) 主流
- 跟asyncio差不多
- 改变装饰器为async 改yield为await
-
# 比如下载图片是时候可以自动切换
import asyncio
async def func1():
print(1)
# 网络io请求
await from asyncio.sleep(2)
print(2)
async def func2():
print(3)
# 网络io请求
await from asyncio.sleep(2)
print(4)
tasks = [
asyncio.ensure_future(func1()),
asyncio.ensure_future(func2()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait())
-
协程的意义
- 一个线程中,遇到IO等待的时间,在去干点别的事情(任务)
- 异步请求url,异步下载
-
异步编程
- 时间循环 (死循环) 检测执行某些代码
-
# 伪代码
任务列表 = []
while True:
for 就绪任务 in 可执行任务
执行就绪任务
for 已完成任务 in 已完成的任务列表
任务列表中移除已完成任务
任务列表为空,循环终止
# 时间循环
import asyncio
loop = asyncio.get_event_loop() # for循环
loop.run_until_complete() # 添加任务
-
快速上手
- 协程函数:(事件循环结合)
- 定义函数的时候async def 函数名 就是协程函数
- 协程对象 协程函数() == 协程对象
-
async def func():
pass
result = func() # 函数并不执行,跟yield一样,跟事件循环结合
# 让时间循环去执行事件
loop = asyncio.get_event_loop() # for循环
loop.run_until_complete(result) # 添加任务
# asyncio.run(result) python3.7之后可以使用
-
await
- await + 可等待的对象(协程对象,Tuture,Task对象)
-
import asyncio
async def func():
print("开始")
response = await asyncio.sleep(2)
print("结束")
asyncio.run(func())
-
import asyncio
async def others():
print("start")
await asyncio.sleep(2)
print("end")
return "返回值"
async def func():
print("start 协程")
response1 = await others()
print("io"+response1)
response2 = await others()
print("io"+response2)
asyncio.run(func())
- await就是等待对象的值,得到结果之后再继续走
- https://juejin.im/post/5c9045a5f265da61125632bf
-
splash
4.扩展延伸知识
- python默认包和pycharm之间差异
-
5.知识内容个人梳理
6.今天都复习了之前的什么内容
3.学习内容
-
django url传参
- url(‘’,args())
-
Django: Unable to get repr for 解决方案
- 重写__str__
-
javasxript跨文件访问
-
python 多个异常嵌套
-
python中 from的两个
- yield from 生成器
- raise TypeError from Class
-
mysql模糊查询
- like 关键字,效率很低,多字段查询也不方便
-
全文检索
- 指定的字段中(多个字段),检索
-
搜索引擎原理
- 搜索引擎会在数据库中对数据进行预处理
- 建立一份索引结构数据,方便查找数据(类似字典的检索)
- 根据索引,查找到数据,找到数据的真实位置
-
Elasticsearch介绍
- 作用:
- 实现全文检索
-
Haystack
-
Post上传的几种方式
-
Django timezone
-
datetime
- p 是prase 解析
- f 是 from 读取
-
asyncio 使用
-
为什么要讲?
- 异步非阻塞,asyncio
- tornado,fastapi django 3.x asgi aiohttp 高性能 往异步发展
-
1.协程
- 介绍协程
- 协程不是计算机中真实存在的,程序员创造的
- 微线程,上下文切换的技术
- 用一个线程在代码之间游走运行,在函数之间进行切换
- 实现协程的模块
-
greenlet早期模块
-
from greenlet import greenlet
def fun1():
print(1)
gr2.swich()
print(2)
gr2.swich()
def fun2():
print(3)
gr1.swich()
print(4)
gr1.swich()
gr1 = greenlet(func1)
gr2 = greenlet(func2)
gr1.switch()
-
greenevent 基于greetlet
- 补充
-
yield 可以伪造成一个协程
-
def func1():
yield 1
yield from func2()
yield 2
def func2():
yield 3
yield from fun1()
yield 4
f1 = func1()
fro item in f1:
print(f1)
-
asyncio 通过装饰器(py3.4)
- 优势:遇到io阻塞,自动切换
-
# 比如下载图片是时候可以自动切换
import asyncio
@asyncio.coroutine
def func1():
print(1)
# 网络io请求
yield from asyncio.sleep(2)
print(2)
@asycnio.coroutine
def func2():
print(3)
# 网络io请求
yield from asyncio.sleep(2)
print(4)
tasks = [
asyncio.ensure_future(func1()),
asyncio.ensure_future(func2()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait())
-
async、await 关键字 (py3.5) 主流
- 跟asyncio差不多
- 改变装饰器为async 改yield为await
-
# 比如下载图片是时候可以自动切换
import asyncio
async def func1():
print(1)
# 网络io请求
await from asyncio.sleep(2)
print(2)
async def func2():
print(3)
# 网络io请求
await from asyncio.sleep(2)
print(4)
tasks = [
asyncio.ensure_future(func1()),
asyncio.ensure_future(func2()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait())
-
协程的意义
- 一个线程中,遇到IO等待的时间,在去干点别的事情(任务)
- 异步请求url,异步下载
-
异步编程
- 时间循环 (死循环) 检测执行某些代码
-
# 伪代码
任务列表 = []
while True:
for 就绪任务 in 可执行任务
执行就绪任务
for 已完成任务 in 已完成的任务列表
任务列表中移除已完成任务
任务列表为空,循环终止
# 时间循环
import asyncio
loop = asyncio.get_event_loop() # for循环
loop.run_until_complete() # 添加任务
-
快速上手
- 协程函数:(事件循环结合)
- 定义函数的时候async def 函数名 就是协程函数
- 协程对象 协程函数() == 协程对象
-
async def func():
pass
result = func() # 函数并不执行,跟yield一样,跟事件循环结合
# 让时间循环去执行事件
loop = asyncio.get_event_loop() # for循环
loop.run_until_complete(result) # 添加任务
# asyncio.run(result) python3.7之后可以使用
-
await
- await + 可等待的对象(协程对象,Tuture,Task对象)
-
import asyncio
async def func():
print("开始")
response = await asyncio.sleep(2)
print("结束")
asyncio.run(func())
-
import asyncio
async def others():
print("start")
await asyncio.sleep(2)
print("end")
return "返回值"
async def func():
print("start 协程")
response1 = await others()
print("io"+response1)
response2 = await others()
print("io"+response2)
asyncio.run(func())
- await就是等待对象的值,得到结果之后再继续走
- https://juejin.im/post/5c9045a5f265da61125632bf
-
splash
4.扩展延伸知识
- python默认包和pycharm之间差异
-
5.知识内容个人梳理
6.今天都复习了之前的什么内容
django url传参
- url(‘’,args())
Django: Unable to get repr for 解决方案
- 重写__str__
javasxript跨文件访问
python 多个异常嵌套
python中 from的两个
- yield from 生成器
- raise TypeError from Class
mysql模糊查询
- like 关键字,效率很低,多字段查询也不方便
全文检索
- 指定的字段中(多个字段),检索
搜索引擎原理
- 搜索引擎会在数据库中对数据进行预处理
- 建立一份索引结构数据,方便查找数据(类似字典的检索)
- 根据索引,查找到数据,找到数据的真实位置
Elasticsearch介绍
- 作用:
- 实现全文检索
Haystack
Post上传的几种方式
Django timezone
datetime
- p 是prase 解析
- f 是 from 读取
asyncio 使用
-
为什么要讲?
- 异步非阻塞,asyncio
- tornado,fastapi django 3.x asgi aiohttp 高性能 往异步发展
-
1.协程
- 介绍协程
- 协程不是计算机中真实存在的,程序员创造的
- 微线程,上下文切换的技术
- 用一个线程在代码之间游走运行,在函数之间进行切换
- 实现协程的模块
-
greenlet早期模块
-
from greenlet import greenlet def fun1(): print(1) gr2.swich() print(2) gr2.swich() def fun2(): print(3) gr1.swich() print(4) gr1.swich() gr1 = greenlet(func1) gr2 = greenlet(func2) gr1.switch()
-
-
greenevent 基于greetlet
- 补充
-
yield 可以伪造成一个协程
-
def func1(): yield 1 yield from func2() yield 2 def func2(): yield 3 yield from fun1() yield 4 f1 = func1() fro item in f1: print(f1)
-
-
asyncio 通过装饰器(py3.4)
- 优势:遇到io阻塞,自动切换
-
# 比如下载图片是时候可以自动切换 import asyncio @asyncio.coroutine def func1(): print(1) # 网络io请求 yield from asyncio.sleep(2) print(2) @asycnio.coroutine def func2(): print(3) # 网络io请求 yield from asyncio.sleep(2) print(4) tasks = [ asyncio.ensure_future(func1()), asyncio.ensure_future(func2()), ] loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait())
-
async、await 关键字 (py3.5) 主流
- 跟asyncio差不多
- 改变装饰器为async 改yield为await
-
# 比如下载图片是时候可以自动切换 import asyncio async def func1(): print(1) # 网络io请求 await from asyncio.sleep(2) print(2) async def func2(): print(3) # 网络io请求 await from asyncio.sleep(2) print(4) tasks = [ asyncio.ensure_future(func1()), asyncio.ensure_future(func2()), ] loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait())
-
-
协程的意义
- 一个线程中,遇到IO等待的时间,在去干点别的事情(任务)
- 异步请求url,异步下载
-
异步编程
- 时间循环 (死循环) 检测执行某些代码
-
# 伪代码 任务列表 = [] while True: for 就绪任务 in 可执行任务 执行就绪任务 for 已完成任务 in 已完成的任务列表 任务列表中移除已完成任务 任务列表为空,循环终止 # 时间循环 import asyncio loop = asyncio.get_event_loop() # for循环 loop.run_until_complete() # 添加任务
-
快速上手
- 协程函数:(事件循环结合)
- 定义函数的时候async def 函数名 就是协程函数
- 协程对象 协程函数() == 协程对象
-
async def func(): pass result = func() # 函数并不执行,跟yield一样,跟事件循环结合 # 让时间循环去执行事件 loop = asyncio.get_event_loop() # for循环 loop.run_until_complete(result) # 添加任务 # asyncio.run(result) python3.7之后可以使用
-
await
- await + 可等待的对象(协程对象,Tuture,Task对象)
-
import asyncio async def func(): print("开始") response = await asyncio.sleep(2) print("结束") asyncio.run(func())
-
import asyncio async def others(): print("start") await asyncio.sleep(2) print("end") return "返回值" async def func(): print("start 协程") response1 = await others() print("io"+response1) response2 = await others() print("io"+response2) asyncio.run(func())
- await就是等待对象的值,得到结果之后再继续走
- 协程函数:(事件循环结合)
- 介绍协程
- https://juejin.im/post/5c9045a5f265da61125632bf
splash
- python默认包和pycharm之间差异