TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #425 · 20 апр.

Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках. Выглядело это примерно так: 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

Hashtags

Резултати

Пронајдени 4 слични објави

Пребарај: #ilva

当前筛选 #ilva清除筛选
Ultimora.net - POLITICS

@ULTIMORAPOLITICS · Post #42198 · 17.11.2022 г., 12:56

È terminato al ministero delle Imprese e del Made in Italy il tavolo sull'ex #Ilva convocato dal ministro Adolfo #Urso in merito alla sospensione delle attività fino al 16 gennaio 2023. @UltimoraPolitics

Hashtags

Maurizio Vezzosi

@mauriziovezzosi · Post #118 · 30.11.2019 г., 15:20

Il mio - altro - videoracconto della giornata della manifestazione che si è svolta ieri a Taranto. Per Ruptly. Taranto (Italy) 29th november 2019 - Hundreds of Ilva workers, Europe's largest steel plant owned by the French-Indian multinational Arcelor-Mittal, held a general strike in Taranto on Friday, to protest against the company's plans to layoff thousands of workers as well as the toxic waste the plant has spewed over the city. "As has always been the case, we demand two basic rights that are written in our Constitution; the right to work and the right to the health," Vincenzo Mercurio a worker and a trade union delegate said. Reports say the protest was joined by a large number of students and activists associated with 'Fridays for Future' and 'Youth for Climate' groups. "The reason why we, students and citizens, are protesting is that we are tired of speaking with people that refuse to respect our rights and to listen to us; people that are busy worrying about their interests, not the people's ones. And we are tired of people showing that they are representing us, although they are just trying to gain our votes," Sara Pierpoli a student and protester said. The Italian government and the world's largest steelmaker Arcelor-Mittal are in dispute over pollution levels and the company's legal position while Rome is considering options to keep the plant open and save thousands of jobs. Video and text by Maurizio Vezzosi #steel#ilva#italsider#italy#climatestrike#fridayforfuture#strikeforclimate https://youtu.be/7xS2zjstqKs

Maurizio Vezzosi

@mauriziovezzosi · Post #116 · 29.11.2019 г., 17:10

#Taranto. I lavoratori del polo siderurgico ex-Ilva (ex-Italsider) scioperano con un'adesione sopra al 70% e scendono in piazza insieme ai giovani per l'ambiente, la salute, il lavoro: una battaglia per l'#Italia contro i saccheggi delle multinazionali. Il mio video-racconto per Il Fatto Quotidiano. #acciaio#ilva#italsider#iri#climatestrike#fridayforfuture#strikeforclimate