随笔分类 -  python

摘要:Log Formatter #!/usr/bin/env python # -*- coding: utf-8 -*- import datetime import os import logging from logging import handlers import json import r 阅读全文
posted @ 2025-02-11 16:07 春树&暮云 阅读(2) 评论(0) 推荐(0) 编辑
摘要:问题 安装paddlenlp报错: subprocess.CalledProcessError python3 -m pip install --upgrade paddlenlp -i https://mirror.baidu.com/pypi/simple 解决方案 检查是否是依赖包seqeva 阅读全文
posted @ 2023-02-15 21:07 春树&暮云 阅读(174) 评论(0) 推荐(0) 编辑
摘要:杂记 NacosTimer: 轮询的方式执行一个回调函数 Watcher: 监听的方式来同步配置 add_config_watcher _init_pulling: 通过新开后台线程,轮询(while True)来拉取数据(队列的方式获取cache_key, content, md5 = self. 阅读全文
posted @ 2023-01-12 10:23 春树&暮云 阅读(480) 评论(0) 推荐(0) 编辑
摘要:现象 基于pytorch的模型服务,本地裸跑代码都是正常的,一旦上docker服务部署后,程序会出现卡死现象 解决 原因是,默认情况下,pytorch会启动宿主机当前的CPU核数作为线程数去运行,一旦该docker服务是和其他服务共享机器,就容易造成CPU占用过高,出现卡死。指定pytorch使用单 阅读全文
posted @ 2022-11-18 16:13 春树&暮云 阅读(369) 评论(0) 推荐(0) 编辑
摘要:方法 trace_err = traceback.format_exc().replace("\n", "\\n") # 日志转换成一行,方便基于request_id追踪 log.error(trace_err) 阅读全文
posted @ 2022-07-28 09:39 春树&暮云 阅读(159) 评论(0) 推荐(0) 编辑
摘要:问题 python -m spacy download en_core_web_sm 安装失败 解决方法 进入https://github.com/explosion/spacy-models/releases/tag/en_core_web_sm-3.3.0 下载数据集 pip install e 阅读全文
posted @ 2022-05-26 21:48 春树&暮云 阅读(381) 评论(0) 推荐(0) 编辑
摘要:问题 对于sanic app,如果不是全局的共享内存,不同worker是分开统计的,导致从接口获取的数据有随机性(时而来源于worker1,时而来源于worker2),多进程模式支持合并输出,需要通过环境变量指定空目录 多进程模式: os.environ["prometheus_multiproc_ 阅读全文
posted @ 2022-04-25 16:50 春树&暮云 阅读(165) 评论(0) 推荐(0) 编辑
摘要:讨论 建议关注官方issues和sanic community Request argument not as a global variable https://github.com/sanic-org/sanic/issues/69 讨论为什么request对象不作为全局变量,需要显式调用的设计 阅读全文
posted @ 2022-04-18 21:51 春树&暮云 阅读(26) 评论(0) 推荐(0) 编辑
摘要:awaesome redis sanic-redis-extension(官方文档) release版本是2018年的(截止20220415) 问题 使用sanic 2.21.3版本会提示不兼容的错误 AttributeError: Setting variables on Sanic instan 阅读全文
posted @ 2022-04-15 16:19 春树&暮云 阅读(241) 评论(0) 推荐(0) 编辑
摘要:问题 python中日志重复打印问题记录 排查 取要区分重复打印的日志格式是否完全一致 完全一致 考虑是否添加了多个handlers,可通过 logger.handlers查看,注意对同一个log模块,import调用路径不一致,可能会产生多个handlers,import尽可能保持同一个调用路径 阅读全文
posted @ 2022-03-20 20:10 春树&暮云 阅读(151) 评论(0) 推荐(0) 编辑
摘要:问题 自定义log formatter, 如添加request_id 方法 定义Logging Filter class ServerFilter(logging.Filter): ... def filter(self, record): record.request_id = xxx retur 阅读全文
posted @ 2022-03-17 22:08 春树&暮云 阅读(622) 评论(0) 推荐(0) 编辑
摘要:类型 Any, Union, Callable, TypeVar, and Generic. 参考文档 python-typing 阅读全文
posted @ 2022-03-14 13:29 春树&暮云 阅读(67) 评论(0) 推荐(0) 编辑
摘要:基础 同步(Sync) vs 异步(Asyncio) 所谓 Sync,是指操作一个接一个地执行,下一个操作必须等上一个操作完成后才能执行。 Async 是指不同操作间可以相互交替执行,如果其中的某个操作被 block 了,程序并不会等待,而是会找出可执行的操作继续执行。 并发 vs 并行 并发(co 阅读全文
posted @ 2021-12-20 19:00 春树&暮云 阅读(58) 评论(0) 推荐(0) 编辑
摘要:1. 备份miniconda安装目录 和 .bashrc文件 2. 新系统拷贝备份的目录,将$miniconda/bin添加到系统path export PATH=$PATH:/home/xx/miniconda3/bin 3. 配置环境 conda init $shell 或者直接将备份的.bas 阅读全文
posted @ 2021-12-17 13:51 春树&暮云 阅读(2121) 评论(0) 推荐(0) 编辑
摘要:结论: performance: marshal > cPickle > json > pickle >>> timeit.timeit("pickle.dumps([1,2,3])","import pickle",number=10000) 0.2939901351928711 >>> time 阅读全文
posted @ 2021-11-29 17:54 春树&暮云 阅读(87) 评论(0) 推荐(0) 编辑
摘要:方法 临时方法 pip install pythonModuleName -i https://pypi.douban.com/simple 永久修改 方式1 修改~/.pip/pip.conf: [global] index-url = https://pypi.douban.com/simple 阅读全文
posted @ 2021-11-29 17:36 春树&暮云 阅读(370) 评论(0) 推荐(0) 编辑
摘要:方法 下载中文字体 ,比如SimHei.ttf 下载完的字体拷贝到matplotlib相应目录 修改 matplotlibrc文件 找到缓存目录,删除缓存,不然始终没法生效!!! 缓存目录位置查看: from matplotlib import get_cachedir print(get_cach 阅读全文
posted @ 2021-10-29 18:23 春树&暮云 阅读(36) 评论(0) 推荐(0) 编辑
摘要:This is due to one of Duckling's dependency JPype. If you dive into the code, you'll see that when starting the JVM using JPype, an argument "convertS 阅读全文
posted @ 2021-10-27 11:07 春树&暮云 阅读(188) 评论(0) 推荐(0) 编辑
摘要:问题 vscode中terminal 显示的python版本(python2.7.x)与cmd窗口python版本(python3.7.x)不一致 解决 打开setting.json文件 搜索“terminal.integrated.env.osx” 编辑"settings.json"文件,添加: 阅读全文
posted @ 2021-10-16 22:30 春树&暮云 阅读(1383) 评论(0) 推荐(0) 编辑

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