[gjc] "interrupt system call" are now handled and cause the function to be retried

This commit is contained in:
Yann Leboulanger 2005-09-28 15:00:01 +00:00
parent 42ffc5d810
commit a8117faf2d
3 changed files with 27 additions and 3 deletions

View File

@ -104,7 +104,7 @@ def get_os_info():
if full_path_to_executable:
command = executable + params
child_stdin, child_stdout = os.popen2(command)
output = child_stdout.readline().strip()
output = helpers.temp_failure_retry(child_stdout.readline).strip()
child_stdout.close()
child_stdin.close()
# some distros put n/a in places so remove them

View File

@ -20,6 +20,7 @@
import sre
import os
import urllib
import errno
import gajim
from common import i18n
@ -32,6 +33,17 @@ except:
_ = i18n._
Q_ = i18n.Q_
def temp_failure_retry(func, *args, **kwargs):
while True:
try:
return func(*args, **kwargs)
except (os.error, IOError), ex:
if ex.errno == errno.EINTR:
continue
else:
raise
def convert_bytes(string):
suffix = ''
# IEC standard says KiB = 1024 bytes KB = 1000 bytes

View File

@ -32,10 +32,22 @@ from simplexml import ustr
from client import PlugIn
from protocol import *
import sys
import os
import errno
DATA_RECEIVED='DATA RECEIVED'
DATA_SENT='DATA SENT'
def temp_failure_retry(func, *args, **kwargs):
while True:
try:
return func(*args, **kwargs)
except (os.error, IOError), ex:
if ex.errno == errno.EINTR:
continue
else:
raise
class error:
"""An exception to be raised in case of low-level errors in methods of 'transports' module."""
def __init__(self,comment):
@ -98,7 +110,7 @@ class TCPsocket(PlugIn):
try: received = self._recv(1024000)
except: received = ''
while select.select([self._sock],[],[],0)[0]:
while temp_failure_retry(select.select,[self._sock],[],[],0)[0]:
try: add = self._recv(1024000)
except: add=''
received +=add
@ -130,7 +142,7 @@ class TCPsocket(PlugIn):
def pending_data(self,timeout=0):
""" Returns true if there is a data ready to be read. """
return select.select([self._sock],[],[],timeout)[0]
return temp_failure_retry(select.select,[self._sock],[],[],timeout)[0]
def disconnect(self):
""" Closes the socket. """