试图弄明白为什么创造和操纵期货是一种糟糕的做法

2024-04-20 00:02:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过阅读PyMotW指南来理解Python中的未来。你知道吗

我昨天问了一个question,在评论中说:

A more serious issue with the guide is that creating and manipulating raw futures is considered bad style in modern async programming.

我试图搜索更多信息,但最接近的是Python guide about Future

The rule of thumb is to never expose Future objects in user-facing APIs, and the recommended way to create a Future object is to call loop.create_future(). This way alternative event loop implementations can inject their own optimized implementations of a Future object.

问题:

为什么创造和操纵期货被认为是不好的做法?原因是否有记录?你知道吗


Tags: andofthetoinloopobjectis
1条回答
网友
1楼 · 发布于 2024-04-20 00:02:14

感谢@user4815162342提供了到Yury Selivanov的async/awaitpresentation的链接。你知道吗

我设法伸手去问他。他是这么说的。你知道吗

The warning is there because Future is a low-level API. You should use it to build async/await facade around existing callbacks-based code. But if you are writing async/await code from scratch, there are higher-level builtin async/await APIs in asyncio that are just easier to use (and less error prone).

相关问题 更多 >