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.
Python and CPU load
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
.
Erik
Erik
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.
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.
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.
