I have a program that uses this library basically does something very simple, like this
receiver = multicast.MulticastUDPReceiver ("192.168.0.2", symbolMCIPAddrStr, symbolMCPort )
while True:
print 'Spinning'
try:
b = MD()
data = receiver.read(1024)
The receiver socket blocks until data comes in, so the print 'Spinning'
only prints once until data is received on the socket. When I ask the OS how much CPU this process is taking, even though it is waiting on the receive, it comes back with:
[idf@node1 ~]$ ps -p 4294 -o %cpu,%mem,cmd
%CPU %MEM CMD
6.3 0.4 python ./mc.py -s EUR/USD
[idf@node1 ~]$
In fact, if I run several of these processes, my computer with two CPU and 8 cores each, all cores go to 100% usage and the computer becomes unusable.
I must misunderstand python's notion of "blocking" because even a do nothing process that should basically be sleeping is taking up lots of CPU.
Is there a more correct way to write this so that programs that are basically waiting for i/o [interrupt-driven] give up the CPU?