FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python and CPU load





Liu
I have a python script that waits for output/events from other applications by sitting in a while loop. However, this seems to be taking way too much cpu load (50%). Is there some method to lower it? Adding sleep intervals in there helps, but i'd rather not use it.
Erik23a86
I'm not sure, but maybe you can set the std input to blocking so that it blocks till there is something to read. But maybe a better solution is to use select. I don't know if you have ever used it, but it "looks" at the input and returns a list of objects which are ready to be read (or write or have an error). Also you can set the timeout property for select. I think select is what you need Razz.

Erik
yoohoo
i am not an experts in python, but as far as i remember select will work on operating system
object that can be signalled. that is, if you are wiating for something specific yuo designed it might not work, but if you are waiting on a sockt/pipe/sync object than you could probably use select.
i am not sure this answer is a hundred percent correct, but you should check exactly what select does
and how it works, and perhaps it will be the best option for you.
another option is using os.sys.WaitForSingleObject (once again, i am not sure this is the exact heirarchy, but the function is a win32 api function called WaitForSingleObject.
Liu
Awesome, thanks guys, I'll give select a try. I've used it before when managing multiple socket connections in C; I wonder why it slipped my mind.
Related topics
Bad Comptuer
Future of FriHost
Cron Jobs
making backups
Mod-gzip
zomg. I think I caused teh downtime.
Which FAST Server
Account Removed
website timing out a little too often!
SpamAssassin on Server 1?
Possible to get CPU load for computer?
Random 100% CPU load for no apparent reason.
scripting help
Using embedded HTML in Python?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.