Strange change in xmlrpclib behavior

Walt Leipold leipold at acm.org
Thu Sep 26 18:39:17 CEST 2002


Late last year, I wrote an app (in Python 2.1) that acquires and 
logs serial data.  It's a standalone app on a remote computer, but 
I wanted to send it an occasional command ("reset", "status?"), so
I included an XML-RPC server handler in its main loop, and set its
socket to nonblocking ("self.socket.setblocking(0)") so it wouldn't
slow down data acquisition.  

The code worked for months.  As of early last week, it no longer 
works.  XML-RPC requests from a remote host (except occasionally
for the very first one after the server starts) raises error 10035
in SocketServer.py ("cannot complete without blocking").  Requests
to the server from localhost work normally.

I've reduced the problem to 43 lines of server code and 18 lines 
of client code, attached below.  It's been tested on six different
machines, and all of them now misbehave.  Other socket-based code 
(like the code that logs the serial data to yet another machine) 
still works.  I don't *think* I'm going crazy, but I could swear 
this code used to work.

Any ideas?  (BTW, it's xmlrpclib v0.9.8, Win2000 SP2 and NT4 SP6.)

------------------------------------------------------------------
"No matter how thin you slice                         Walt Leipold
it, it's still baloney."                           leipold at acm.org
------------------------------------------------------------------

aserver.py:
===========
#!/usr/bin/python
import SocketServer
import xmlrpcserver
import time

class BozoServerHandler(xmlrpcserver.RequestHandler):
    def call(self,method,params):
        try:
            server_method = getattr(self,method)
        except:
            raise AttributeError,"No method named %s!" % (method,)
        return server_method(method, params)

    def status(self,method,args):
        global done,statcount,itercount
        now = time.time()
        statcount += 1
        return time.strftime("%H:%M:%S -- ",time.localtime(now)) + \
            "%d requests in %d iterations." % (statcount,itercount)

    def die(self,method,args):
        global done,statcount,itercount
        done = 1
        return "Aaargh!"

class bozoSocketServer(SocketServer.TCPServer):
    """A TCPServer with a non-blocking socket."""
    # Use the 'server_close()' method to close this server.
    def __init__(self,addr,handler):
        SocketServer.TCPServer.__init__(self,addr,handler)
        self.socket.setblocking(0)

server = bozoSocketServer(('',1234),BozoServerHandler)
done = 0
statcount = 0
itercount = 0

while not done:
    time.sleep(0.1) # Between serial i/o requests...
    itercount += 1
    # Handle a single XML-RPC request, if present.
    server.handle_request()
server.server_close()

aclient.py:
===========
#!/usr/bin/python
import sys
import xmlrpclib
import time

if len(sys.argv) != 2:
    host = "localhost"
else:
    host = sys.argv[1]
s = xmlrpclib.Server("http://%s:1234" % (host,))

try:
    for i in xrange(0,100):
        print s.status()
        time.sleep(1.5)
except KeyboardInterrupt:
    pass
print s.die()



More information about the Python-list mailing list