avatar
Articles
288
Tags
201
Categories
0

karr's blog
Search

karr's blog

SQLAlchemy会话与事务控制:互斥锁和共享锁
Created2024-06-08
for updateSQLAlchemy 的 Query 支持 select … for update / share 12session.Query(User).with_for_update().first()session.Query(User).with_for_update(read=True).first() 完整形式 1with_for_update(read=False, nowait=False, of=None) read 是标识加互斥锁还是共享锁. 当为 True 时, 即 for share 的语句, 是共享锁. 多个事务可以获取共享锁, 互斥锁只能一个事务获取.有”多个地方”都希望是”这段时间我获取的数据不能被修改, 我也不会改”, 那么只能使用共享锁. nowait 其它事务碰到锁, 是否不等待直接”报错”. of 指明上锁的表, 如果不指明, 则查询中涉及的所有表(行)都会加锁. 扩展with_for_update实际对应mysql的 SELECT ... FOR UPDATE 语句, 但是在使用时要注意, 由于InnoDB 预设是 ...
BasicColumn 自定义行内容
Created2024-06-06
BasicColumn 配置1234567const columns: BasicColumn[] = [ { title: 'yourTitle', dataIndex: 'yourDataIndex', slots: {customRender: 'yourSlotName'}, },]; 页面使用12345<BasicTable @register="register"> <template #yourSlotName="{ record }"> {{ record['yourDataIndex'] }} </template></BasicTable>
python 检测编码 & 正确解码 bytes
Created2024-06-05
12345678def test(): import chardet data = b"\xe4\xb8\xad\xe6\x96\x87" if isinstance(data, bytes): encoding = chardet.detect(data)["encoding"] print("encoding", encoding) text = data.decode(encoding, "ignore") print("text", text)
web监听窗口滚动事件,并判断是否滚动到底部
Created2024-06-01
1234567891011121314const handleScroll = () => { let scrollTop = document.documentElement.scrollTop || document.body.scrollTop; let clientHeight = document.documentElement.clientHeight; let scrollHeight = document.documentElement.scrollHeight; if (scrollTop + clientHeight >= scrollHeight) { console.log("滚动到底部了") }}onMounted(() => { window.addEventListener('scroll', handleScroll)})onUnmounted(() => { win ...
python给图片加上背景
Created2024-05-31
1234567891011121314def add_background_to_the_image(): from PIL import Image # 加载原始图片 image = Image.open('img.png') # 创建背景 background = Image.new('RGB', (2000, 2000), (255, 255, 255)) # 将原始图片放置在背景上 background.paste(image, (100, 100)) # 保存结果图片 background.save('img_res.png')
eslint 配置文件
Created2024-05-31
安装1npm install --save-dev eslint .eslintignore1234567891011121314*.shnode_modules*.md*.woff*.ttf.vscode.ideadist/public/docs.husky.local/binDockerfile .eslintrc.js1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980// @ts-checkconst {defineConfig} = require('eslint-define-config');module.exports = defineConfig({ root: true, env: { browser: true, n ...
使用 aiohttp & asyncio 实现协程并发下载
Created2024-05-30
协程并发下载12345678910111213141516171819202122232425import aiohttpimport asynciourls = [ "https://www.baidu.com", "https://www.baidu.com", "https://www.baidu.com",]async def async_download(url, idx): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: with open(f"{time.time()}.html", "wb") as f: f.write(await resp.content.read()) print(f"download {idx&# ...
FastAPI如何返回文件字节流
Created2024-05-29
在 FastAPI 中,返回文件字节流的主要方式包括使用 StreamingResponse 和 FileResponse。这两者都可以用于返回二进制数据,例如图像文件。 StreamingResponse: 适用于以流式方式发送数据,对于大型文件特别有用,因为它允许在数据生成时就开始发送,而不必等到整个数据集都可用。1234567891011import iofrom fastapi.responses import StreamingResponse@app.get("/get_demo_image")def get_demo_image(): image_data = open("face.png", "rb").read() return StreamingResponse( content=io.BytesIO(image_data), media_type="image/png" ) FileResponse: 适用于返回文件,可以从文件系统路径中 ...
python 处理图片去重
Created2024-05-28
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455def process_file(img_path): """ 处理图片去重 """ try: phasher = PHash() # 生成图像目录中所有图像的二值hash编码 encodings = phasher.encode_images(image_dir=img_path) # print(encodings) # 对已编码图像寻找重复图像 duplicates = phasher.find_duplicates(encoding_map=encodings) # print(duplicates) only_img = [] # 唯一图片 like_img = [] ...
解决 argparse 获取参数与通过 uvicorn 启动时冲突问题
Created2024-05-24
问题描述产生冲突的原因是因为 uvicorn 启动时候会解析命令行参数,而 argparse 也会解析命令行参数,导致冲突。具体表现为,当使用 uvicorn 启动时候,argparse 获取不到参数。 即在代码中如果在启动了的 uvicorn 程序中调用了sys.argv[1:], 则会报错在 argparse 中的参数列表初始化中有这么一段代码,也是导致报错的原因 1234567def parse_known_args(self, args=None, namespace=None): if args is None: # args default to the system args args = _sys.argv[1:] else: # make sure that args are mutable args = list(args) 解决方案在初始化 argparse 时候,传入参数 [] 即可解决问题 12parser = argparse.ArgumentParser(add_help=add_h ...
1…789…29
avatar
karr
世界那么大,我想去看看。
Articles
288
Tags
201
Categories
0
gitee
Announcement
This is my Blog
Recent Post
Git报错: Failed to connect to github.com port 443 解决方案2025-03-30
AI Agent 系统架构图2025-03-28
固定整个页面只有100%的高度,不能进行下拉,当组件的内容超过100%时候在个自组件内部加上滚动条2025-03-12
html保证背景色铺满整个页面2025-03-12
importlib.import_module强制从文件加载2025-03-07
Tags
vue3 滚动 错误码 GROUP BY hexo java jwt 抖音 filter 架构 gap lock 前端 opencv Windows unicode Android Studio javascript 优化 vue 救猫咪 react-props-warning json_extract uvicorn 线程 图片去重 JSON mysqlclient npm Mutable go aiohttp rewrite 疫情防控 操作系统 滚动条 OTP 无人机 ORM text css
Archives
  • March 20256
  • February 20252
  • January 20253
  • November 20242
  • October 20243
  • September 20247
  • August 202410
  • July 202423
Info
Article :
288
UV :
PV :
Last Update :
©2024 - 2025 By karr
Framework Hexo|Theme Butterfly
Search
Loading the Database