[Spread-users] Spread python poll() taking almost 100% CPU

Brian Moseley bcm at maz.org
Fri Oct 1 18:06:09 EDT 2004


George Schlossnagle wrote:
> 
> On Oct 1, 2004, at 5:23 PM, Brian Moseley wrote:
>>
>> i was having the same problem as the original poster, so i switched to 
>> the poll/sleep technique. seems to work fine.
>>
>> i'd prefer to not have to poll tho, for the reason you mentioned. 
>> using poll, i have to continuously check that the connection is still 
>> connected, and reconnect if it somehow dropped away underneath. yuck.
> 
> 
> In C you can actually just poll() (with a timeout of course) on mbox, 
> which is a file descriptor.

ah yeah, forgot to mention that i'm using java. but i think i've found a 
way, by nulling the connectiong whenever i catch InterruptedIOException 
from receive() and then checking for a null connection whenever i next 
need to receive(). like so:

     public void run() {
         while (isRunning) {
             try {
                 if (sconn != null) {
                     receive(sconn.receive());
                 }
                 else {
                     // somehow we lost the connection. keep trying to
                     // reconnect until we get it back.
                     try {
                         log.warn("reconnecting");
                         connect();
                     } catch (Exception e) {
                         // wait a little bit, then try to reconnect
                         Thread.sleep(50);
                     }
                 }
             } catch (InterruptedIOException e) {
                 // if we're still in running mode, then spread
                 // probably dropped the connection on us. re-establish
                 // it. otherwise, we're shutting down.
                 if (! isRunning) {
                     sconn = null;
                 }
             } catch (SpreadException e) {
                 log.error("cannot receive Spread message", e);
             }
         }
     }




More information about the Spread-users mailing list