Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.4.2
- Device: #Pong
- Released: 08/01/26
⬇️ Download: ROM
📖 Changelogs: Here
🆘 Support: Discord | Telegram
🏷 Tags: #AOSP#ROM#EvoX#Official
✍️Notes:
- Use latest NOS 3 firmware! Not 4.0
- Use OrangeFox recovery to install if sideloading!
- Gapps is included, do not flash again
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & Ghost & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.2
- Device: #Pong
- Released: 23/09/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again
- Use latest NOS 3 firmware
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.7
- Device: #Pong
- Released: 09/06/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelog: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR2#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Use latest NOS 3 firmware
- Dolby is included
- Clean Flash is required from 10.3 or lower
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.6
- Device: #Pong
- Released: 14/05/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR2#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Use latest NOS 3 firmware
- Dolby is included
- Clean Flash is required for this update
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.5.2
- Device: #Pong
- Released: 03/02/26
⬇️ Download: Gapps | Vanilla
🛟 Recovery: Here
📖 Changelogs: Here
🆘 Support: Discord | Telegram
🏷 Tags: #AOSP#ROM#EvoX#Official#QPR1
✍️Notes:
- Firmware is included! (NOS 4.0)
- Sideloading/USB in recovery works as intended now
- Gapps is included, do not flash again
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & Ghost & HELLBOY for Glyph
- HELLBOY for Kernel base
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.3
- Device: #Pong
- Released: 22/02/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR1#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Firmware is included
- Dolby is included
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat @NothingPhone2
🔔 Updates @NothingPhone2Updates