简体中文
Telegram
PPython Talk

Python Talk

@python_talk · 群组 · 科技 · 收录于 2026/07/04
58成员
37 339索引中的消息
O
"Friendship ended with Zig, now Rust is my best friend"
  1. A
    Browsing LinkedIn this weekend is gonna be even more painful.. "AI rewrote an entire framework from Zig to Rust. This is why coding is outdated..." 🫩
整个讨论串 · 2 条回复 →
G
Hey, i got a sync function that i want to call asyncronously in a loop def api_call() ... # Do api call for chunk in batched(parse_csv(local_path), BATCH_LIMIT): # Do 10 api calls in parallel using async I tried with different things but couldn't get anything working. How do you do it?
  1. C
    Don't do it. Running a synchronous function in async context breaks your loop in a way that the other concurrent functions won't run until you're done. This is likely what you have experienced when trying to make it work. Run the code in a different thread, that puts it outside of the context of the asynchronous loop. Try asyncio.to_thread and asyncio.gather.
    1. A
      I think the question is more like, I have a sync function, how do I parallel-ize it such that I can handle it like an async function without doing the threads etc. stuff myself.
      1. C
        asyncio.to_thread is the abstraction. The answer only changes if the synchronous function is developer-owned and can be converted to a native asynchronous function. Unless of course there's an option to just pick an asynchronous library (assuming the synchronous function comes from a library) to replace the synchronous function.
整个讨论串 · 6 条回复 →
G
can i do? with asyncio.TaskGroup() as tg: tg.create_task(asyncio.to_thread(call_api()))
  1. C
    Because the library is synchronous. If you can't replace your library with an asynchronous library, asyncio.to_thread is the answer.
整个讨论串 · 2 条回复 →

来自搜索索引的公开信息流 ChatCrawler ——“公开 Telegram 的 Google”;随着该社群被抓取而更新。 时间为 UTC。

仅限公开内容,使用 Telegram 官方 API。 关于 · 常见问题 · 索引限制 · 移除页面 · 目录 · 搜索 · 计算方法