Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
Sources from the #Druze community in #Syria have indicated that a delegation of approximately 100 prominent Druze figures is preparing to visit the occupied Golan Heights this Friday.
During the visit, the delegation is expected to meet with Sheikh Mowafaq Tarif, the spiritual leader of the Druze in #Israel, along with other key figures from the community. They are also scheduled to visit a religious site in the region.
According to Reuters, this visit is seen as the latest sign of strengthening ties between Israel and the Druze community, particularly in the wake of the ceasefire in Lebanon and the political shifts in Syria following the ousting of former President Bashar al-Assad.
As of now, Israel’s Foreign Ministry has not issued an official confirmation regarding the visit.
The leader of the #Druze community in #Syria, Sheikh Hikmat al-Hijri, declared on Thursday that there is "no harmony or agreement with the authorities in #Damascus" while remaining silent of rapproachment with #Israel.
Although he Druze religious authorities in Sweida have rejected any rapprochement with the Israeli occupation, Druze figures visited the occupied Golan this week for the first time in 50 years, despite a religious prohibition issued by the clerics of the Syrian village of Hadar against those participating in the visit.
Sheikh Hikmat al-Hijri did not taken a clear stance but stated that he "will move in a direction that serves the interests of the Druze community."
"Syria Al-Julani regime released kidnapped Druze kids after months of detention
The Jolani regime has released two Druze brothers, Yanal Bashar al-Haddad (15) and Qais Bashar al-Haddad (13), who had been detained at Adra Prison in #Damascus since their arrest during the attack on #Suwayda on July 15, 2025.
Its worth noting that terriost regime kidnapped and killed a lot of Druze and Alawites kids and women (see links on X post)
❗️ Note that the terrorist regime refuse to hold accountable the militants who committed massacres against the #Alawites or #Druze, and label them as “mojahdin” =jihadists, because fighting against “infidel” minorities is considered a heroic act in their eyes."
https://x.com/SyJusticeArc/status/2006461460713488503
#Syria🇸🇾: #Druze militias posing with captured "General Security Service" (former #HTS) vehicles in Tal Hadid, west of #Sweida (#Suwayda).
Some of the Druze fighters can be seen with a #Hungary-made 🇭🇺 AK-63D rifle, Soviet AKS-74U carbine and PG-7VM Anti-Tank rocket.
https://x.com/war_noir/status/1951991045517877364
"A new massacre against the #Alawites in the city of #Latakia, in the #Dattour neighborhood, al-Mazar junction.
I beg all segments of the Syrian people, especially the #Druze, #Kurds, and any remaining members of the #Sunni community who still have a little humanity left in their hearts, to take to the streets in protest to stop these massacres against the innocent. These #massacres are not from yesterday, they are happening today, and as of moments ago, they are still being carried out by Syrian members of Hay’at Tahrir al-Sham #HTS, wearing their official uniforms.
Please, save those who remain."
https://t.me/CoastSyrian24/771
Systematic Attacks on Religious Minorities' Shrines and Places of Worship in Syria
W #Hama: An extremist terrorist group has destroyed a religious shrine belonging to the #Alawite community, known as “Sheikh Muhammad al-Maghribi,” located in the village of #Asila in Masyaf, in the Ghab Plain in the rural countryside of Hama Governorate, yesterday 21 March 2026.
#Alawite: It is worth noting that attacks on Alawite religious shrines began following the fall of the regime, reaching their peak during the #massacres carried out against Alawites on the Syrian coast by al-Jolani’s forces. Incidents of assault on Alawite shrines have continued repeatedly, to the point where barely a month passes without an incident involving the bombing, desecration, or burning of shrines across various Alawite regions.
#Druze: Similarly, shrines belonging to the Druze community were subjected to comparable attacks, including vandalism, arson, and bombings, during the massacres of July 2025 in #Suwayda, carried out by the forces of al-Jolani’s terrorist regime.
#Christians: A church in #Damascus was also bombed in June 2025, in addition to attacks on churches in #Homs and the rural Homs region in the #alQusayr area. The massacres that took place in As-#Suwayda likewise saw the burning and destruction of three churches.