Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
News: #CBE says digital platforms handled over nine trillion birr, accounting for 87% of half-year transactions
The Commercial Bank of Ethiopia (CBE) says transactions conducted through its digital banking platforms surpassed nine trillion birr in the first half of the 2025/26 fiscal year, accounting for nearly 88 percent of the bank’s total transfers and payments.
The figures were disclosed during CBE’s half-year performance review conference, where Wegayehu Gebremariam, Vice President for Strategic Planning and Transformation, presented the bank’s six-month performance report.
According to Wegayehu, digital channels facilitated more than nine trillion birr in transactions during the reporting period, representing 87.9 percent of total banking transactions.
He said CBE accounted for 73 percent of the country’s total digital transactions and payments in the previous fiscal year, adding that current trends indicate the bank is likely to maintain its....
Read more: https://addisstandard.com/?p=54768
News: #CBE launches digital wallet for inward foreign currency transfers
The Commercial Bank of #Ethiopia (CBE), in partnership with local company StarPay Financial Services, has launched a digital wallet application, “CBE Connect,” to facilitate the transfer of foreign currency into the country.
Ephrem Mekuria, Executive Vice President for Corporate Services at the Commercial Bank of Ethiopia, attended the launch ceremony yesterday, alongside ambassadors and senior bank officials.
Ephrem encouraged customers to use legal channels instead of informal foreign exchange markets during his speech at the event. He added that CBE Connect allows users to send money easily using international payment cards such as Visa and Mastercard, as well as through licensed foreign remittance agents.
The bank noted that the digital wallet aims to support international customers, boost foreign currency inflows, and provide the Ethiopian diaspora with a simple, cost-free platform to send and receive remittances.
Ethiopia’s Commercial Bank Announces Digital Banking Disruptions. Read more.
https://borkena.com/2026/05/03/ethiopias-commercial-bank-announces-digital-banking-disruptions/#Ethiopia#bank#CBE#EthiopianNews
#Policy_Brief: Consolidate or Collapse: Mergers and acquisitions as strategic lifeline for #Ethiopian banks
In this policy brief, Samson Hailu contends that Ethiopia’s banking sector is entering a critical phase, as consolidation —particularly through mergers and acquisitions— shifts from a private-sector discussion to a policy priority of the #NBE under Governor Eyob Tekalign.
Although the sector has expanded to 31 banks, the #CBE continues to dominate, leaving smaller institutions vulnerable. Stress tests highlight significant capital and liquidity risks, reinforcing the author’s warning that “consolidation is not merely a strategic choice but a requirement for survival.”
He recommends that smaller “third-generation” banks form partnerships with larger private banks and endorses a “guided voluntary” approach, designed not to mandate consolidation but to facilitate market-led combination.
https://addisstandard.com/?p=56167