没有繁忙等待的Queue.Queue式课程 [英] Queue.Queue-like class without the busy-wait

查看:70
本文介绍了没有繁忙等待的Queue.Queue式课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人编写了Queue.Queue替换程序,以避免繁忙等待?

它是否使用特定于os的API无关紧要(例如

WaitForMultipleObjects) 。到目前为止,我做了一些谷歌搜索并没有找到




因为我知道有人会问:不,忙碌的等待还没有我的应用程序中出现了一个

问题。我只是对阅读代码感兴趣。


p

Has anyone written a Queue.Queue replacement that avoids busy-waiting?
It doesn''t matter if it uses os-specific APIs (eg
WaitForMultipleObjects). I did some googling around and haven''t found
anything so far.

Because I know someone will ask: no, the busy-waiting hasn''t been a
problem in my app. I''m just interested in reading the code.

p

推荐答案

Paul L Du Bois写道:
Paul L. Du Bois wrote:
有没有人写过Queue.Queue替换,以避免忙碌等待?
它是否使用特定于os的API(例如
) WaitForMultipleObjects的)。到目前为止,我做了一些谷歌搜索,并没有找到任何东西。

因为我知道有人会问:不,忙碌的等待还没有成为
我的应用中的问题。我只是对阅读代码感兴趣。
Has anyone written a Queue.Queue replacement that avoids busy-waiting?
It doesn''t matter if it uses os-specific APIs (eg
WaitForMultipleObjects). I did some googling around and haven''t found
anything so far.

Because I know someone will ask: no, the busy-waiting hasn''t been a
problem in my app. I''m just interested in reading the code.




我不相信术语忙碌等待适用于此。

忙碌等待(根据我的经验)你在哪里运行

紧密循环而不释放CPU,消耗所有

CPU时间可用。


我相当肯定,虽然Queue(以及在Python中等待的其他东西

)确实有一个循环,你会发现

它不是一个忙碌的等待循环,你肯定不会在等待期间获得100%的CPU使用率。它在等待的时候会越来越长时间地睡觉

,如果threading._Condition中的代码是任何指示,那么



-Peter



I don''t believe the term "busy-wait" applies here.
Busy-waiting is (in my experience) where you run in
tight loops without releasing the CPU, consuming all
CPU time available.

I''m fairly certain that while Queue (and other things
that wait in Python) does have a loop, you''ll find that
it''s not a busy-waiting loop and you definitely don''t
get 100% CPU usage during the wait. It goes to sleep
for increasingly large periods of time while waiting,
if the code in threading._Condition is any indication.

-Peter


Peter Hansen写道:
Peter Hansen wrote:
我不相信忙碌等待这个词。适用于此。
[说明]
I don''t believe the term "busy-wait" applies here.
[Explanation]




是的,嗯,你是对的。我打算叫它

slacker-waiting但是我不想太可爱。


p



Yes, well, you''re right. I was thinking of calling it
"slacker-waiting" but didn''t want to come off too cute.

p


Op 2005-03-24, Paul L. Du Bois schreef< po ****** @ gmail.com>:
Op 2005-03-24, Paul L. Du Bois schreef <po******@gmail.com>:
有没有人写过Queue.Queue替换品,避免忙碌等待?
它没有'无论是否使用特定于os的API(例如,WaitForMultipleObjects)。我做了一些谷歌搜索,到目前为止还没有找到任何东西。
Has anyone written a Queue.Queue replacement that avoids busy-waiting?
It doesn''t matter if it uses os-specific APIs (eg
WaitForMultipleObjects). I did some googling around and haven''t found
anything so far.




我开始一次,使用线程模块中的Timer类来

打破锁定。但是,Timer类使用相同类型的

睡眠轮询循环来延迟执行并允许中间取消
作为Queue.Queue中使用的循环,所以那不是

增益。


我还是玩过这个想法,但是没有做任何事情

从那以后。


-

Antoon Pardon



I started once, using the Timer class in the Threading Module to
break the lock. However the Timer class uses the same kind of
sleep-polling loop, to delay the exection and allow an intermediate
cancel, as the loop that is used in Queue.Queue, so that was no
gain.

I have still played with the idea, but haven''t worked anything out
since then.

--
Antoon Pardon


这篇关于没有繁忙等待的Queue.Queue式课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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