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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Reasons for Python async/await

135 点作者 hittaruki大约 10 年前

5 条评论

avolcano大约 10 年前
For context on this, check out PEP 492: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0492&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0492&#x2F;</a><p>It&#x27;s a really exciting proposal. AFAIK, it&#x27;d make Python 3 the first mainstream imperative scripting language to have these async&#x2F;await concepts built-in (there is a similar proposal for JavaScript&#x2F;ES7 built on top of generators and promises[1]). While I&#x27;ve commented before about how asyncio is still a bit more nascent than I&#x27;d like, I&#x27;m really excited to see where the community takes it.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;lukehoban&#x2F;ecmascript-asyncawait" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lukehoban&#x2F;ecmascript-asyncawait</a>
评论 #9579249 未加载
评论 #9578865 未加载
评论 #9579139 未加载
评论 #9578674 未加载
评论 #9580969 未加载
评论 #9581460 未加载
评论 #9579699 未加载
tosh大约 10 年前
Related: <a href="http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?ref=rss&amp;id=2747873" rel="nofollow">http:&#x2F;&#x2F;queue.acm.org&#x2F;detail.cfm?ref=rss&amp;id=2747873</a><p>This is the ACM Queue paper about async&#x2F;await in Dart (iirc according to Erik Meijer the cleanest implementation of the concept so far).
cbsmith大约 10 年前
The problem I have with async with is that you&#x27;ve already got issues with the syntax for &quot;with&quot; context managers and generators.<p><pre><code> def my_generator(): with something() as bar: for x in baz(): yield bar(x) # context manager will call bar.__exit__() before the second time through this loop. </code></pre> It&#x27;d make a LOT more sense to just make &quot;with&quot; understand when it is in a continuation and only invoke __exit__() when the continuation is being destroyed.
评论 #9580701 未加载
评论 #9581674 未加载
mherrmann大约 10 年前
It seems to me like this is a feature that will only be used by 1% of Python programmers. I&#x27;m lacking a lot of context but personally I&#x27;d much prefer it if Guido spent his time fixing the Python 2&#x2F;3 conundrum. And even though these proposed changes are Python 3 only, the fact that only so few people will use them doesn&#x27;t do much in that regard.
评论 #9582293 未加载
thristian大约 10 年前
The nice thing about Python generator functions was that they didn&#x27;t need a lot of syntax - if a function contains the &quot;yield&quot; keyword, it&#x27;s a generator, otherwise it&#x27;s not.<p>Given how closely tied generators are with async&#x2F;await, why do we need &quot;async def&quot;? Isn&#x27;t the presence of &quot;await&quot; or &quot;async for&quot; or &quot;async with&quot; enough to mark a function as asynchronous?
评论 #9581884 未加载
评论 #9580241 未加载