Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
Evangelical Christianity and the right-wing Catholic Church during the Nazi era are two extremely ugly ones. One is in the name of being anti-Semitic, and the other is in the name of misappropriating Judaism.
04.03.2024
#rightwing
📰 Israel’s Right-Wing Split Is Now a Branding War
The Hungarian lesson for Israel is simple: if you can’t beat the ruling camp by going left, take its patriotism away from it. That is how Peter Magyar broke Orbán’s machine — not by preaching anti-right unity, but by occupying the same national space and making the old monopoly look stale.
That is exactly what the new Israeli “Right State” project is trying to do. Edelstein, Kahlon, Erdan, and Haskel are not a centrist rebellion; they are an attempt to say, “We’re right-wing, just not Bibi,” and to pull security-minded voters away from Netanyahu without surrendering the language of nation, state, and order.
The trouble is that Israeli voters remember the last five times someone tried to sell them that package. Bennett, Saar, and Lapid all tested the same lane, but Netanyahu kept the hard-right base, stayed the default prime minister in the minds of right-leaning voters, and used fragmentation on the other side as his best campaign asset.
Bennett’s latest liberal turn makes the problem sharper. Public transport on Shabbat and civil marriage, including same-sex marriage, may sound modern in Tel Aviv, but to the old religious-national audience it looks like a costume change — and Yair Golan’s warm welcome only makes Bennett look even more alien to the right.
That is why this new bloc may hurt the left more than it hurts Netanyahu. It could strip votes from the anti-Bibi camp, split the “right, but not Bibi” lane again, and still fail to build the one thing the opposition actually needs: a durable field that runs from center to soft right to hard right without collapsing into personal rivalries.
Netanyahu’s health story only adds another layer. The real question is whether the opposition can turn competence into a message before the prime minister turns uncertainty into victimhood and keeps the national conversation locked on himself.
#Israel#Netanyahu#Bennett#Lapid#rightwing#elections
📱American Оbserver - Stay up to date on all important events
🇺🇸
Video (#1 above) surfaced last week of several rich upper class kids holidaying in the exclusive #German resort island of #Sylt, singing along to a tune called "L'Amour toujours" by Italian DJ #Gigi D'Agostino, but using words associated with the German Extreme #RightWing
"Ausländer raus,
Deutschland den Deutschen,
Ausländer Raus"
"Foreigners out,
Germany for Germans,
Foreigners out!"
The German media and Gov't went into overdrive and the 5 rich kids involved, were soon identified, named&shamed, and have now been totally and utterly "ge-#canceled", losing jobs and probably any hope of a quiet future.
The re-worded tune however has now gone completely viral, spawning numerous other memes and parodies (videos #3, #4, #5 above)
It's a very clear example of the "Barbara #Streisand" Effect in action