def _wait_for_read_with_timeout(self, fd): """ Wait while the read file descriptor gets ready :param fd: File descriptor to read :raises StorletTimeout: Exception raised when it times out to cancel the existing task :raises StorletRuntimeException: Exception raised when it fails to cancel the existing task """ try: with StorletTimeout(self.timeout): r, w, e = select.select([fd], [], []) except StorletTimeout: exc_type, exc_value, exc_traceback = sys.exc_info() # When there is a task already running, we should cancel it. if self.task_id: try: self._cancel() except StorletRuntimeException: self.logger.warning( 'Task %s timed out, but failed to get canceled' % self.task_id) pass six.reraise(exc_type, exc_value, exc_traceback) if fd not in r: raise StorletRuntimeException('Read fd is not ready')
def read_with_timeout(self, size): try: with StorletTimeout(self.timeout): chunk = os.read(self.fd, size) except StorletTimeout: if self.cancel_func: self.cancel_func() self.close() raise except Exception: self.close() raise return chunk
def _wait_for_write_with_timeout(self, fd): """ Wait while the write file descriptor gets ready :param fd: File descriptor to write :raises StorletTimeout: Exception raised when it times out to cancel the existing task :raises StorletRuntimeException: Exception raised when it fails to cancel the existing task """ with StorletTimeout(self.timeout): r, w, e = select.select([], [fd], []) if fd not in w: raise StorletRuntimeException('Write fd is not ready')
def _write_input_data(self, fd, data_iter): try: # double try/except block saving from unexpected errors try: with self._open_writer(fd) as writer: for chunk in data_iter: with StorletTimeout(self.timeout): writer.write(chunk) except (OSError, TypeError, ValueError): self.logger.exception('fdopen failed') except IOError: # this will happen at sort of broken pipe while writer.write self.logger.exception('IOError with writing fd %s' % fd) except StorletTimeout: self.logger.exception( 'Timeout (%s)s with writing fd %s' % (self.timeout, fd)) except Exception: # _write_input_data is designed to run eventlet thread # so that we should catch and suppress it here self.logger.exception('Unexpected error at writing input data')
def wait(self): """ Wait while scope's sandbox is starting :raises StorletTimeout: the sandbox has not started in sandbox_wait_timeout """ try: with StorletTimeout(self.sandbox_wait_timeout): while True: rc = self.ping() if (rc != 1): time.sleep(self.sandbox_ping_interval) continue else: return except StorletTimeout: self.logger.exception("wait for sandbox %s timedout" % self.scope) raise
def dummy_wait_failure(*args, **kwargs): raise StorletTimeout()