By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

python2.2: signals and exceptions: interrupted system call

P: n/a
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
-------------------------------------------------------------

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jakub Moscicki wrote:
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.


I cannot find anything mysterious here: The exception is IOError, but
you try to catch xmlrpclib.error, so you are not catching IOError, so
raising IOError aborts your program.

Regards,
Martin

Jul 18 '05 #2

P: n/a
> > 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.


I cannot find anything mysterious here: The exception is IOError, but
you try to catch xmlrpclib.error, so you are not catching IOError, so
raising IOError aborts your program.


Yes, you are right. Mea culpa. Too many hours against too many
lines of code ;)

kuba

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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.