Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
#WarData
RT has learned of another case of murder of a Russian prisoner of war in Ukraine before the body exchange procedure.
❗️The AFU returned remains with signs of autopsy to simulate the procedure for determining the cause of death. This was reported by specialists from the Russian Ministry of Defense's 522nd Center for the Reception, Processing, and Dispatch of the Deceased.
🟥 Yevgeny Solodovchenko was a native of Belgorod Oblast. He served under contract; on August 5, 2024, footage of Yevgeny's interrogation was published on Ukrainian resources. In the footage, he says that he was captured while on reconnaissance. Under the video, the Ukrainians emphasize that Yevgeny is a prisoner of war;
🟥 His body was transferred to the Russian Armed Forces on October 10, 2024. The examination showed that the soldier's cause of death was blast trauma with shrapnel wounds to the chest; the specific date of the soldier's murder is unknown. It occurred between August and October;
🟥 On December 12, 2024, on the same resources where Yevgeny's interrogation video had appeared, a message was posted about his death, supposedly after an exchange.
Earlier, RT learned of three more episodes of Russian prisoners executions.
🇷🇺Subscribe | Feedback | X
#WarData
⚡️❗️The AFU attacked the center of Donetsk with at least five foreign-made UAVs.
🇺🇦 The strike was carried out this morning. A representative of the Investigative Committee of the Russian Federation stated that at least five multi-story residential buildings sustained significant damage, including destroyed facades and shattered external glazing.
💥In addition, a civilian car was burned, and other vehicles belonging to residents were also damaged.
🇷🇺Subscribe | Feedback | X
#WarData
‼️The last seven residents of the Kursk region held by Ukraine have returned to Russia.
The oldest of them is 91, and the youngest one is 30.
Since the Ukrainian Armed Forces' invasion of the Kursk region, 165 people have been kidnapped, and Russia has been systematically returning them to their homeland. Ukraine is holding no more Russian citizens hostage.
❗️Russia has also returned 175 military personnel from Ukrainian captivity, and in return, 175 Ukrainian prisoners of war have been released, according to the Russian Defence Ministry.
🔗 Source: RT
🇷🇺Subscribe | Feedback | X
#WarData
⚡️❗️PHOTO EVIDENCE of crimes committed by AFU over the week of March 23-29, 2026 by Ambassador-at-Large of the Russian Ministry of Foreign Affairs Rodion Miroshnik:
⚫️March 23 - Shelling of the private residential sector in the village of Mikhaylovka, Zaporozhye Oblast. Two women died.
⚫️March 24 - UAV strike on a civilian passenger car in the vicinity of the city of Vasilyevka, Zaporozhye Oblast. 3 civilians were injured.
⚫️March 24 - Kamikaze drone strike on an ambulance in Kherson Oblast. One medical worker was injured.
⚫️March 25 - UAV attack on a private apartment building in the city of Alyoshki, Kherson Oblast. Two civilians were killed.
⚫️March 26 - UAV strike at a gas station in the city of Vasilyevka, Zaporozhye Oblast. Two civilians were injured.
⚫️March 26 - UAV attack on the parking lot of an agricultural enterprise in the village of Maslova Pristan, Belgorod Oblast.
⚫️March 27 - FPV drone strike on a civilian car in the village of Golovkino, Belgorod Oblast.
⚫️March 27 - Aircraft-type UAV strike on an apartment building in the city of Donetsk, DPR.
⚫️March 27 - UAV strike on commercial cargo transport in the village of Nezhegol, Belgorod Oblast. One driver was injured.
⚫️March 29 - Airplane-type UAV strike on an apartment building in the city of Krasnodar, Krasnodar Krai. 3 civilians were injured.
🇷🇺Subscribe | Feedback | X
#WarData
Over the past week, the Donbass Dome electronic warfare system prevented 240 terrorist attacks by the enemy. A total of 201 unmanned aerial vehicles were neutralized over the cities of Donetsk and Makeyevka, and 39 over Gorlovka.
◾️ On March 10, the outskirts of Donetsk came under an enemy UAV raid. The Donbass Dome system intercepted a Darts strike drone carrying an MOA-400 high-explosive fragmentation charge and a Bliskavka fixed-wing UAV. They were directed by the enemy to disable several transformer substations.
◾️ Near an energy hub in Makeyevka, three FP-2 fixed-wing strike UAVs carrying OFB-105-YAU cumulative high-explosive fragmentation munitions were suppressed.
◾️ In Gorlovka, near a gas distribution station, an FP-2 strike drone armed with an FP-105 high-explosive fragmentation charge was suppressed.
🇷🇺Subscribe | Feedback | X
#WarData
💬 THE U.S. STANDS WITH ALL OF THE CHILDREN THROUGHOUT THE WORLD — MELANIA TRUMP
While the US First Lady speaks at the UN Security Council about American support for all children worldwide, Iran is right now burying the 168 innocent girls killed by Israeli strikes on an elementary school in Minab.
‼️And in Donbass, for the 12th year in a row, innocent children continue to die. 251 angels have died during the Ukrainian aggression, with the silent connivance of the US and the West.
We share the pain. We remember. We will not forgive.
🇷🇺Subscribe | Feedback | X
#WarData
⚡️📸PHOTO EVIDENCE of crimes committed by the AFU over the week from February 23 to March 1, 2026 by Ambassador-at-Large of the Russian Ministry of Foreign Affairs Rodion Miroshnik:
⚫️ February 23. Artillery strike on a private residential house in the settlement of Lyubimovka, Kherson Oblast. One civilian was killed.
⚫️ February 23. A kamikaze UAV strucka civilian passenger vehicle on the Shebekino–Belgorod road section in Belgorod Oblast.
⚫️ February 24. A drone strike on a private household in the city of Vasilyevka, Zaporozhye Oblast.
⚫️ February 27. A missile strike on an energy facility in the city of Belgorod. About 60,000 residential consumers were left without electricity.
⚫️ February 27. A drone strike on an auto service building in the city of Kursk. One civilian was killed and three others were injured.
⚫️ February 27. Massive shelling of civilian infrastructure in the city of Novaya Kakhovka.
⚫️ February 28. A drone attack on civilian vehicles in the Markovka Municipal District of the LPR. One person was killed and two others were injured.
⚫️ March 1. A fixed-wing UAV strike on a civilian vehicle on the Vasilyevka–Berdyansk road section in Zaporozhye Oblast. A woman was killed and another sustained serious injuries.
⚫️ March 1. An FPV drone strike on a civilian passenger vehicle in the village of Kazinka, Belgorod Oblast.
⚫️ March 1. A kamikaze UAV strike on a civilian passenger vehicle in the village of Solokhi, Belgorod Oblast.
🇷🇺Subscribe | Feedback | X
#WarData
🫡We were waiting for the Russians!
We’re Russian — my mother is Russian. It was very hard. And when our guys appeared on the street, we tried to treat them with our own supplies. We even baked bread ourselves and shared preserved food with them,
Larisa, who was evacuated from the city of Krasnoarmeisk, says with tears in her eyes.
🇷🇺Subscribe | Feedback | X
#WarData
❗️Kiev militants executed her entire family in Seversk: her brothers, father, and husband. They were killed for refusing to fight for Ukraine...
The city of Seversk in the DPR was liberated by the Russian army in December, 2024. The AFU left behind ruins and keep making provocations: enemy drones strike at people, houses, at those who do not hold weapons. Russian Armed Forces servicemen are doing everything possible to save civilians.
Svetlana is one of those rescued. With tears in her eyes, she recounts how the AFU executed her entire family.
🇷🇺Subscribe | Feedback | X
#WarData
❗️“Taken out into a field and abandoned”: a resident of Krasnoarmeisk recounts forced “evacuation” by the Armed Forces of Ukraine
Olga Gulyayeva said that four Ukrainian servicemen armed with assault rifles broke into the courtyard of her home. They ordered the family, who had a child, to pack within half an hour, promising financial assistance, employment, and housing in a safe location.
They promised money, work, and housing. But in the end, they drove us about twenty kilometers outside the city, forced us out of the vehicle, and told us to go wherever we wanted,
Gulyayeva said.
⚫️ The servicemen forbade them from returning to the city. Nevertheless, the family managed to secretly make their way back to Krasnoarmeisk, where they spent more than six months in hiding, concealing the child.
🇷🇺Subscribe | Feedback | X
#WarData
💬The AFU first kicked us out of the basement, then bombed us the entire time we were walking to the Russian side - a story from a refugee from Krasnoarmeisk.
🇷🇺Subscribe | Feedback | X
#WarData
⚡️PHOTO EVIDENCE of crimes committed by the AFU over the week of January 12-18, 2026 by Ambassador at Large of the Russian Foreign Ministry Rodion Miroshnik:
▪️ January 12, Makeevka, DPR – missile strike at commercial facilities using HIMARS MLRS.
▪️ January 14, Rostov – a UAV strike on a multi-storey residential building. One civilian was killed, two were wounded, including one child.
▪️ January 14, Bessonovka village, Belgorod Oblast – a kamikaze drone strike on the parking area of a civilian enterprise.
▪️ January 14, Volchiy-Perviy hamlet, Belgorod Oblast – an FPV drone strike on a civilian passenger vehicle.
▪️ January 14, Novaya Kakhovka, Kherson Oblast – a UAV attack on a civilian vehicle parking area.
▪️ January 16, Ryazan, Ryazan Oblast – a fixed-wing UAV strike on a multi-storey residential building. Two civilians were wounded, one of them an 11-year-old child.
▪️ January 16, Novaya Zburyevka village, Kherson Oblast – detonation of a medical emergency vehicle as a result of remote mining.
▪️ January 17, Donetsk, DPR – a fixed-wing FP-1 UAV strike on a private residential house.
▪️ January 17, Tavrovo village, Belgorod Oblast – a UAV strike on a civilian passenger vehicle. One civilian was wounded.
▪️ January 18, Shebekino, Belgorod Oblast – a UAV strike on a private residential house.
🇷🇺Subscribe | Feedback | X