线程不平衡 [英] Thread imbalance

查看:77
本文介绍了线程不平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行多个线程的程序。其中一个必须每天完成

(指定时间,通常为1秒)。拥有一个

线程的重点就是这样做。但是,我注意到以下情况。如果有另外一部分程序处于活动状态,那么这个程序就会消失,这个程序只会在每隔4-5秒运行一次。或者它可能是
在计算过程中等待一段时间。我怎样才能确保不会发生这个
?这个线程使用很少的处理能力,因此如果有办法,可以将
设置为高优先级。谢谢!

解决方案

Tuvas写道:

我有一个运行多个线程的程序。其中一个必须每天完成(指定时间,通常为1秒)。有一个
线程的重点是这样做。但是,我注意到以下情况。当该程序的另一部分处于活动状态时,该线程会暂停,即,它只会每4-5秒运行一次,或者它可能会等待
等待在计算过程中。我怎样才能确保不会发生这种情况?该线程使用很少的处理能力,因此如果有办法,可以将其设置为高优先级。谢谢!



我认为使用python线程可能很困难,只需根据
python控制全局解释器锁的方式。


我可能有的一个建议是让python更频繁地释放全局

解释器锁,你可以在这里阅读全局

解释器锁:

http://docs.python.org /api/threads.html


您可能也可以在

组合中使用一些计时器/条件构造,例如


线程A:

如果watchdogTimer():

conditionVar.aquire()

conditionVar。通知(threadB)

conditionVar.release()


ThreadB:

而(1):

conditionVar.aquire()

conditionVar.wait()

functionToDoSomething()


这当然是伪python,如果你想知道这些物品

我建议你查阅python手册。


-carl


-


Carl J. Van Arsdall
cv ***** ****@mvista.com

构建和发布

MontaVista软件


< blockquote> Tuvas写道:

等待计算过程中的lul。我怎样才能确保不会发生这种情况?该线程使用很少的处理能力,因此如果有办法,可以将其设置为高优先级。谢谢!




Python不适合同时执行/计算线程,但是它不会那么糟糕 - 你有很多吗?计算密集型线程?


如果你在类似unix的平台上运行,请参阅

signal()和SIGALRM的文档 - 也许它会有所帮助你的任务。


Ivan Voras写道:

Tuvas写道:

等待计算过程中的lul。我怎样才能确保不会发生这种情况?该线程使用很少的处理能力,因此如果有办法,可以将其设置为高优先级。谢谢!



Python不适合并发执行/计算线程,但它不应该那么糟糕 - 你有很多计算密集型线程吗?




以防万一将来的任何人都会读到这个声明,对于

这个记录我想说这显然是一个问题意见或

解释,因为在我看来Python对于线程来说是优秀的*

(通常被认为是同时执行,所以我认为

这个形容词也是多余的。)


伊万,是什么让你说Python对线程有害?

资格是否同时执行/计算?有什么意义我错过了吗?

-Peter


I have a program running several threads. One of them must be done
every (Specified time, usually 1 second). The whole point to having a
thread is do this. However, I''ve noticed the following. When there is
another part of the program that is active, this thread slips into
disuse, ei, it''s only ran about once every 4-5 seconds, or perhaps it
waits for a lul in the computing process. How can I ensure that this
does not happen? This thread uses little processing power, so it could
be set to a high priority, if there is a way to do this. Thanks!

解决方案

Tuvas wrote:

I have a program running several threads. One of them must be done
every (Specified time, usually 1 second). The whole point to having a
thread is do this. However, I''ve noticed the following. When there is
another part of the program that is active, this thread slips into
disuse, ei, it''s only ran about once every 4-5 seconds, or perhaps it
waits for a lul in the computing process. How can I ensure that this
does not happen? This thread uses little processing power, so it could
be set to a high priority, if there is a way to do this. Thanks!


I think that might be difficult using python threads simply based on how
python controls the global interpreter lock.

One suggestion I might have is to have python release the global
interpreter lock more frequently, you can read about the global
interpreter lock here:

http://docs.python.org/api/threads.html

You might also be able to use some timer/condition construct in
combination with this, something like

Thread A:
if watchdogTimer():
conditionVar.aquire()
conditionVar.notify(threadB)
conditionVar.release()

ThreadB:
while(1):
conditionVar.aquire()
conditionVar.wait()
functionToDoSomething()

This is pseudo python of course, if you need to know about these objects
I would suggest consulting the python manual.

-carl

--

Carl J. Van Arsdall
cv*********@mvista.com
Build and Release
MontaVista Software


Tuvas wrote:

waits for a lul in the computing process. How can I ensure that this
does not happen? This thread uses little processing power, so it could
be set to a high priority, if there is a way to do this. Thanks!



Python is bad for concurrently executing/computing threads, but it
shouldn''t be that bad - do you have lots of compute-intensive threads?

If you are running on a unix-like platform, see documentation for
signal() and SIGALRM - maybe it will help your task.


Ivan Voras wrote:

Tuvas wrote:

waits for a lul in the computing process. How can I ensure that this
does not happen? This thread uses little processing power, so it could
be set to a high priority, if there is a way to do this. Thanks!



Python is bad for concurrently executing/computing threads, but it
shouldn''t be that bad - do you have lots of compute-intensive threads?



Just in case anyone coming along in the future reads this statement, for
the record I''d like to say this is obviously a matter of opinion or
interpretation, since in my view Python is *excellent* for threads
(which are generally considered "concurrently executing", so I think
that adjective is redundant, too).

Ivan, what makes you say that Python is bad for threads? Did the
qualifcation "concurrently executing/computing" have some significance
that I missed?

-Peter


这篇关于线程不平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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