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 is locked until data arrives, so print 'Spinning' prints only once until the data is received on the socket. When I ask the OS how much CPU this process takes, even if it is waiting to be received, it returns 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 CPUs and 8 cores each, all cores go for 100% use, and the computer becomes unusable.
I must misunderstand the concept of python about โlockingโ, because even doing nothing, which basically needs to sleep, takes a lot of processor.
Is there a more correct way to write this so that programs that are mostly waiting for I / O [with interruptions] refuse the processor?
source share