python2.2: signals and exceptions: interrupted system call

Jakub Moscicki moscicki at mail.cern.ch
Sat Oct 4 05:29:22 EDT 2003


Hello,

A small problem: I get a signal during a system call (from xmlrpclib -> 
httplib) and an exception "IOError: [Errno 4] Interrupted system call" is 
raised (this is system dependant, on other machine it does not raise this 
exception). I have my own signal handler so I want to simply ignore this 
exception if it occures. But for a reason mysterious to me I cannot catch 
this exception in the main's program try block.

Anybody knows what's wrong? Code listings below.

Thanks,

kuba

-------------------
python2.2 client.py
<ServerProxy for xyz.com:8001/RPC2>
Signal handler called with signal 14
I made 51 calls in 3 seconds
Traceback (most recent call last):
  File "client.py", line 31, in ?
    server.echo('hello')
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/xmlrpclib.py", 
line 821, in __call__
    return self.__send(self.__name, args)
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/xmlrpclib.py", 
line 975, in __request
    verbose=self.__verbose
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/xmlrpclib.py", 
line 842, in request
    errcode, errmsg, headers = h.getreply()
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/httplib.py", 
line 752, in getreply
    response = self._conn.getresponse()
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/httplib.py", 
line 595, in getresponse
    response.begin()
  File 
"/tmp/DIANE/install/anaphe_top/specific/redhat73/gcc-3.2/PublicDomainPackages/2.0.0/lib/python2.2/httplib.py", 
line 119, in begin
    line = self.fp.readline()
IOError: [Errno 4] Interrupted system call

 -------------------
If you want to reproduce the problem try this with python2.2:

--
client.py
--

import xmlrpclib

SERVER = "http://localhost:8001"
server = xmlrpclib.ServerProxy(SERVER) # local server

timeout = 3

print server

import signal, os

global terminate

def handler(signum, frame):
    global terminate
    print 'Signal handler called with signal', signum
    terminate = 1

signal.signal(signal.SIGALRM, handler)
signal.alarm(timeout)

cnt = 0
terminate = 0
try:
    try:
        while not terminate:
            server.echo('hello')
            cnt += 1
    except xmlrpclib.Error, v:
        print "ERROR", v
finally:
    print "I made %d calls in %d seconds" % (cnt,timeout)


--
server.py
--

import SimpleXMLRPCServer

SERVER = 'localhost'
log = 1

server = SimpleXMLRPCServer.SimpleXMLRPCServer((SERVER, 8001), logRequests=log)

try:
    server.register_function(lambda x: x, 'echo')
    server.serve_forever()
finally:
    server.socket.close()

-- 
-------------------------------------------------------------
      mow mi KUBA     call me KUBA     appelle-moi KUBA
-------------------------------------------------------------





More information about the Python-list mailing list