随笔分类 -  Python

摘要:降低插件版本 pip install urllib3==1.26.16 -i https://pypi.tuna.tsinghua.edu.cn/simple 阅读全文
posted @ 2024-02-13 22:36 LeoShi2020 阅读(54) 评论(0) 推荐(0) 编辑
摘要:pip install SQLAlchemy 阅读全文
posted @ 2023-04-05 17:30 LeoShi2020 阅读(21) 评论(0) 推荐(0) 编辑
摘要:''' 异步迭代器 ''' import asyncio class MyRange: def __init__(self, total=0): self.total = total self.count = 0 def __aiter__(self): return self async def 阅读全文
posted @ 2023-03-31 10:40 LeoShi2020 阅读(40) 评论(0) 推荐(0) 编辑
摘要:''' 异步上下文管理 ''' import asyncio class ContextManager: def __init__(self): self.conn = None async def action(self): return self.conn async def __aenter_ 阅读全文
posted @ 2023-03-31 10:34 LeoShi2020 阅读(24) 评论(0) 推荐(0) 编辑
摘要:''' 同步上下文管理器 ''' import time class ContextManager: def __init__(self): self.conn = None def action(self): return self.conn def __enter__(self): # 链接数据 阅读全文
posted @ 2023-03-31 10:25 LeoShi2020 阅读(14) 评论(0) 推荐(0) 编辑
摘要:import asyncio import time from concurrent.futures import ThreadPoolExecutor def download_img(url): print(f"下载图片:{url}") time.sleep(1) print(f"下载完成:{u 阅读全文
posted @ 2023-03-31 10:12 LeoShi2020 阅读(90) 评论(0) 推荐(0) 编辑
摘要:import time from concurrent.futures import ThreadPoolExecutor def download_img(url): print(f"下载图片:{url}") time.sleep(1) print(f"下载完成:{url}") def main( 阅读全文
posted @ 2023-03-31 10:08 LeoShi2020 阅读(30) 评论(0) 推荐(0) 编辑
摘要:''' concurrent.futures 模块提供异步执行可调用对象高层接口,使用线程池 ThreadPoolExecutor 或 进程池 ProcessPoolExecutor 来实现异步。目的是保证服务稳定运行的前提下提供最大的并发能力。 ''' from concurrent.future 阅读全文
posted @ 2023-03-31 09:20 LeoShi2020 阅读(21) 评论(0) 推荐(0) 编辑
摘要:import asyncio from asyncio import Future async def f1(): print(1) await asyncio.sleep(3) print(2) return "f1" def callback(f: Future): f.get_loop().s 阅读全文
posted @ 2023-03-31 09:09 LeoShi2020 阅读(68) 评论(0) 推荐(0) 编辑
摘要:import asyncio from functools import partial from asyncio import Future async def f1(): print(1) await asyncio.sleep(2) print(2) return "f1" def callb 阅读全文
posted @ 2023-03-30 19:19 LeoShi2020 阅读(185) 评论(0) 推荐(0) 编辑
摘要:相同点: 从功能上看, asyncio.wait 和 asyncio.gather 实现的效果是相同的。 不同点: 使用方式不一样,wait需要传一个可迭代对象,gather传多个元素 wait比gather更底层,gather可以直接得到结果,wait先得到future再得到结果 wait可以通过 阅读全文
posted @ 2023-03-30 17:25 LeoShi2020 阅读(168) 评论(0) 推荐(0) 编辑
摘要:import asyncio async def f1(): print(1) await asyncio.sleep(2) print(2) async def f2(): print(3) await asyncio.sleep(2) print(4) async def main(): pri 阅读全文
posted @ 2023-03-30 16:54 LeoShi2020 阅读(27) 评论(0) 推荐(0) 编辑
摘要:import asyncio import aiohttp async def download_img(session, url): file_name = url.rsplit('/')[-1] print(f"下载图片:{file_name}") await asyncio.sleep(2) 阅读全文
posted @ 2023-03-30 15:58 LeoShi2020 阅读(26) 评论(0) 推荐(0) 编辑
摘要:import asyncio async def f1(): print(1) await asyncio.sleep(2) print(2) async def f2(): print(3) await asyncio.sleep(2) # 等 可以等待的对象 print(4) tasks = [ 阅读全文
posted @ 2023-03-30 15:34 LeoShi2020 阅读(23) 评论(0) 推荐(0) 编辑
摘要:from gmssl import sm4, sm3 def sm3_hash(message: str): """ 国密sm3加密 :param message: 消息值,bytes类型 :return: 哈希值 """ msg_list = [i for i in bytes(message.e 阅读全文
posted @ 2023-03-29 20:26 LeoShi2020 阅读(2223) 评论(0) 推荐(0) 编辑
摘要:import pymysql from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Column, String, Integer from sqlalc 阅读全文
posted @ 2023-03-28 18:45 LeoShi2020 阅读(366) 评论(0) 推荐(0) 编辑
摘要:import pymysql from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Column, String, Integer from sqlalc 阅读全文
posted @ 2023-03-28 09:51 LeoShi2020 阅读(351) 评论(0) 推荐(0) 编辑
摘要:import pymysql from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Column, String, Integer from sqlalc 阅读全文
posted @ 2023-03-28 09:33 LeoShi2020 阅读(353) 评论(0) 推荐(0) 编辑
摘要:from urllib.parse import quote_plus as urlquote # 指定连接的MySQL数据库 PASSWORD = 'root@demo.demo' DATABASE_URL = f"mysql://root:{urlquote(PASSWORD)}@10.105. 阅读全文
posted @ 2023-03-26 23:56 LeoShi2020 阅读(281) 评论(0) 推荐(0) 编辑
摘要:import pymysql # 获取连接 conn = pymysql.connect( host='10.105.212.1', port=3306, user='root', password='DemoDemo', database='db', charset='utf8' ) cursor 阅读全文
posted @ 2023-03-26 23:25 LeoShi2020 阅读(105) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示