TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Gradually migrating Python code to asyncio

3 点作者 erwald大约 3 年前

1 comment

uniqueuid大约 3 年前
The post is a good introduction, and in particular this sentence summarizes the core problem:<p>&quot;You can always call normal functions from coroutines, and you can always await coroutines from other coroutines, but scheduling coroutines from normal functions requires some care.&quot;<p>Helper functions such as run_in_executor(), ensure_future() etc. are absolutely critical for navigating the added complexity.<p>However! Im my experience, it is inevitable that one needs to re-consider the entire architecture of an app when adding async parts. The reason is that you will end up implicitly creating and removing choke points that may be surprising.<p>For example, if you had a thread pool before, the concurrency was cumbersome but easy to reason about. If you&#x27;re now sending coroutines to the loop, you might end up having a large number (thousands, millions) waiting for some shared resource in your code or consuming memory.<p>Async python has a lot of advantages and I honestly like the style of programming it encourages, but I feel that many of the examples and tutorials are missing the point by showing map&#x2F;reduce-style workflows which are trivial anyways. The hard parts are continuously running systems with loops and complex logic flow.