为什么我们需要gevent.queue? [英] Why do we need gevent.queue?

查看:185
本文介绍了为什么我们需要gevent.queue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Gevent的理解是,它只是并发而非并行。我对诸如Gevent和AsyncIO之类的并发机制的理解是,Python应用程序中没有任何一个同时执行。

My understanding of Gevent is that it's merely concurrency and not parallelism. My understanding of concurrency mechanisms like Gevent and AsyncIO is that, nothing in the Python application is ever executing at the same time.

最接近的是,调用非阻塞IO方法,并且在等待该调用以返回Python应用程序中的其他方法时可以执行。同样,Python应用程序中的所有方法均未真正同时执行Python代码。

The closest you get is, calling a non-blocking IO method, and while waiting for that call to return other methods within the Python application are able to be executed. Again, none of the methods within the Python application ever actually execute Python code at the same time.

话虽如此,为什么需要gevent.queue?在我看来,Python应用程序确实不需要担心一次访问一个队列实例的多个Python方法。

With that said, why is there a need for gevent.queue? It sounds to me like the Python application doesn't really need to worry about more than one Python method accessing a queue instance at a time.

我确定在某些情况下我看不到gevent.queue修复了,我只是好奇那是什么。

I'm sure there's a scenario that I'm not seeing that gevent.queue fixes, I'm just curious what that is.

推荐答案

尽管您是正确的,在一个Python进程中没有两个语句可以同时执行,但是您可能希望确保系列语句是原子执行的,或者您可能想对某些语句的执行强加一个顺序,在这种情况下, gevent.queue 之类的东西就变得有用。 此处

Although you are right that no two statements execute at the same time within a single Python process, you might want to ensure that a series of statements execute atomically, or you might want to impose an order on the execution of certain statements, and in that case things like gevent.queue become useful. A tutorial is here.

这篇关于为什么我们需要gevent.queue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆