Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
from fastapi.concurrency import run_in_threadpool
async def execute(data: DataRequest) -> DataResponse:
try:
result = await run_in_threadpool(sync_function, data)
return DataResponse(data=result)
except Exception as e:
return DataResponse(
error=str(e),
success=False,
)
В общем работает нормально. Для всех вызовов под капотом используется общий тредпул, всё работает предсказуемо.
Но потребовалось изменить количество запускаемых в пуле потоков (по умолчанию создается 40 воркеров).
Так как дело происходит с FastAPI, делается это через lifespan используя настройки anyio:
import anyio
@asynccontextmanager
async def lifespan(app: FastAPI):
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = 100
yield
# если вдруг нужно вернуть обратно
limiter.total_tokens = 40
Зачем менять количество воркеров?
- уменьшить, если оперативки мало (один тред занимает ~8мб)
- увеличить чтобы выдержать нагрузку
Если есть предложения получше при тех же вводных - предлагайте😉
#async
OnePlus Archive
OnePlus Archive is a firmware repository for OnePlus phones offering stock OTA images and full firmware packages. It includes archived files for specific partition images to save bandwidth and storage, along with boot/init_boot images for rooting, un-rooting, flashing stock firmware and aftermarket development purposes.
🔗 Links:
- GitHub repo
Developer: Spike
❤️ Support the Project
If this project makes your life easier, here are a few quick ways to show some love:
⭐ Star the repo/app
☕ Buy a coffee for the developer
🛠 Contribute code, issues, or pull-requests
🏷 Tags: #Android#OnePlus#Firmware
Oneplus Archive
This project provides official, unmodified OnePlus stock firmware images for supported models, ideal for rooting, flashing custom ROM(s) and more
⚙️ Repo Link: Here
👤 Maintainer: Spike & Team
#oneplus#firmware#boot#otaimage#root
#shell#buildroot_external_tree#firmware#ingenic#ip_camera#ipc#ipcamera
Thingino is free, open-source firmware designed specifically for IP cameras using Ingenic SoC chips. It customizes the software to fit each supported camera model, making the camera easier to use and more efficient. You can build the firmware yourself using the provided instructions and tools, and there is a helpful web interface to control camera features like pan, tilt, night mode, and streaming. This gives you more control and flexibility over your camera without relying on proprietary software. It supports many camera models, and the community offers resources like a wiki, chat groups, and development guides to help you get started and customize your device. This benefits you by providing a customizable, transparent, and community-supported alternative to closed camera firmware.
https://github.com/themactep/thingino-firmware