NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle88 views

Как вызвать фактически синхронную и блокирующую функцию `process_chunk` из асинхронного кода так, чтобы не блокировать event loop?

Practice

AI answer

Move the blocking call to a separate thread, for example by using asyncio.to_thread:

result = await asyncio.to_thread(process_chunk, chunk)

This allows the event loop to continue running other tasks while the function is working. For older Python versions, you can use loop.run_in_executor(...).