From a8117faf2d08cd8acbc3ce9962855e208614c370 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 28 Sep 2005 15:00:01 +0000 Subject: [PATCH] [gjc] "interrupt system call" are now handled and cause the function to be retried --- src/common/connection.py | 2 +- src/common/helpers.py | 12 ++++++++++++ src/common/xmpp/transports.py | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 1148f256d..5ac7b00d4 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -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 diff --git a/src/common/helpers.py b/src/common/helpers.py index d2c481691..de1b2bee9 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -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 diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index ff28e325f..bfd695b4e 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -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. """