当前位置: 首页>>代码示例>>Python>>正文


Python errno.EINTR属性代码示例

本文整理汇总了Python中errno.EINTR属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EINTR属性的具体用法?Python errno.EINTR怎么用?Python errno.EINTR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在errno的用法示例。


在下文中一共展示了errno.EINTR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _receive_device

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _receive_device(self):
        """Receive a single device from the monitor.

        Return the received :class:`Device`, or ``None`` if no device could be
        received.

        """
        while True:
            try:
                device_p = self._libudev.udev_monitor_receive_device(self)
                return Device(self.context, device_p) if device_p else None
            except EnvironmentError as error:
                if error.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
                    # No data available
                    return None
                elif error.errno == errno.EINTR:
                    # Try again if our system call was interrupted
                    continue
                else:
                    raise 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:monitor.py

示例2: deliver_dnotify

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def deliver_dnotify(self, dnstring, _recurse = 0):
        if self.s == None:
            self.connect()
        if _recurse > _MAX_RECURSE:
            raise Exception('Cannot reconnect: %s', self.spath)
        if not dnstring.endswith('\n'):
            dnstring += '\n'
        while True:
            try:
                self.s.send(dnstring)
                break
            except socket.error as why:
                if why[0] == EINTR:
                    continue
                elif why[0] in (EPIPE, ENOTCONN, ECONNRESET):
                    self.s = None
                    return self.deliver_dnotify(dnstring, _recurse + 1)
                raise why
        # Clean any incoming data on the socket
        if len(self.poller.poll(0)) > 0:
            try:
                self.s.recv(1024)
            except:
                pass
        return 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:27,代码来源:DNRelay.py

示例3: _retry_on_intr

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _retry_on_intr(fn, timeout):
        if timeout is None:
            deadline = float("inf")
        else:
            deadline = monotonic() + timeout

        while True:
            try:
                return fn(timeout)
            # OSError for 3 <= pyver < 3.5, select.error for pyver <= 2.7
            except (OSError, select.error) as e:
                # 'e.args[0]' incantation works for both OSError and select.error
                if e.args[0] != errno.EINTR:
                    raise
                else:
                    timeout = deadline - monotonic()
                    if timeout < 0:
                        timeout = 0
                    if timeout == float("inf"):
                        timeout = None
                    continue 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:23,代码来源:wait.py

示例4: readinto

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def readinto(self, b):
        """Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.

        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        """
        self._checkClosed()
        self._checkReadable()
        if self._timeout_occurred:
            raise IOError("cannot read from timed out object")
        while True:
            try:
                return self._sock.recv_into(b)
            except timeout:
                self._timeout_occurred = True
                raise
            except error as e:
                n = e.args[0]
                if n == EINTR:
                    continue
                if n in _blocking_errnos:
                    return None
                raise 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:27,代码来源:_socketio.py

示例5: _read_bytes

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _read_bytes(self, num_bytes):
        self._sock.settimeout(self._read_timeout)
        while True:
            try:
                data = self._rfile.read(num_bytes)
                break
            except (IOError, OSError) as e:
                if e.errno == errno.EINTR:
                    continue
                self._force_close()
                raise err.OperationalError(
                    CR.CR_SERVER_LOST,
                    "Lost connection to MySQL server during query (%s)" % (e,))
        if len(data) < num_bytes:
            self._force_close()
            raise err.OperationalError(
                CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
        return data 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:20,代码来源:connections.py

示例6: test_send_command_unreliable_network

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def test_send_command_unreliable_network(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.EAGAIN, ""),
            b"this is\n",
            b"a\n",
            IOError(errno.EINTR, ""),
            b" fake response\n\n",
            None
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.sendall.assert_called_once_with(b"a command\n")

        self.assertEqual(
            result,
            """this is
a
 fake response"""
        ) 
开发者ID:wglass,项目名称:collectd-haproxy,代码行数:26,代码来源:test_connection.py

示例7: wait

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def wait(self, timeout):
        try:
            self.notify()
            ret = select.select(self.wait_fds, [], [], timeout)
            if ret[0]:
                if self.PIPE[0] in ret[0]:
                    os.read(self.PIPE[0], 1)
                return ret[0]

        except select.error as e:
            if e.args[0] == errno.EINTR:
                return self.sockets
            if e.args[0] == errno.EBADF:
                if self.nr < 0:
                    return self.sockets
                else:
                    raise StopWaiting
            raise 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:sync.py

示例8: sleep

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def sleep(self):
        """\
        Sleep until PIPE is readable or we timeout.
        A readable PIPE means a signal occurred.
        """
        try:
            ready = select.select([self.PIPE[0]], [], [], 1.0)
            if not ready[0]:
                return
            while os.read(self.PIPE[0], 1):
                pass
        except select.error as e:
            if e.args[0] not in [errno.EAGAIN, errno.EINTR]:
                raise
        except OSError as e:
            if e.errno not in [errno.EAGAIN, errno.EINTR]:
                raise
        except KeyboardInterrupt:
            sys.exit() 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:arbiter.py

示例9: _read

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _read(self, N):
        # Starting with Python 3 open with buffering=0 returns a FileIO object.
        # FileIO.read behaves like read(2) and not like fread(3) and thus we
        # have to handle the case that read returns less data as requested here
        # more carefully.
        data = b("")
        while len(data) < N:
            try:
                d = self.__file.read(N - len(data))
            except IOError, e:
                # read(2) has been interrupted by a signal; redo the read
                if e.errno == errno.EINTR:
                    continue
                raise

            if d is None:
                # __file is in non-blocking mode and no data is available
                return data
            if len(d) == 0:
                # __file is in blocking mode and arrived at EOF
                return data

            data += d 
开发者ID:mortcanty,项目名称:earthengine,代码行数:25,代码来源:posix.py

示例10: _read_bytes

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _read_bytes(self, num_bytes):
    self._sock.set_readtimeout(self._read_timeout)
    while True:
        try:
            data = self._rfile.read(num_bytes)
            break
        except (IOError, OSError) as e:
            if e.errno == errno.EINTR:
                continue
            raise err.OperationalError(
                2013,
                "Lost connection to MySQL server during query (%s)" % (e, ))
    if len(data) < num_bytes:
        raise err.OperationalError(
            2013, "Lost connection to MySQL server during query")
    return data 
开发者ID:zhu327,项目名称:greentor,代码行数:18,代码来源:mysql.py

示例11: non_polling_read

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def non_polling_read(self, read_length, timeout):
        data = ''
        bytes_left = read_length

        while bytes_left > 0:
            try:
                ready, _, _ = select.select([self._sock.fileno()], [], [], timeout)

                if not ready:
                    raise NetBIOSTimeout

                received = self._sock.recv(bytes_left)
                if len(received) == 0:
                    raise NetBIOSError, ('Error while reading from remote', ERRCLASS_OS, None)

                data = data + received
                bytes_left = read_length - len(data)
            except select.error, ex:
                if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
                    raise NetBIOSError, ('Error occurs while reading from remote', ERRCLASS_OS, ex[0]) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:22,代码来源:nmb.py

示例12: _peek_unlocked

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _peek_unlocked(self, n=0):
        want = min(n, self.buffer_size)
        have = len(self._read_buf) - self._read_pos
        if have < want or have <= 0:
            to_read = self.buffer_size - have
            while True:
                try:
                    current = self.raw.read(to_read)
                except IOError as e:
                    if e.errno != EINTR:
                        raise
                    continue
                break
            if current:
                self._read_buf = self._read_buf[self._read_pos:] + current
                self._read_pos = 0
        return self._read_buf[self._read_pos:] 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:_pyio.py

示例13: _flush_unlocked

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def _flush_unlocked(self):
        if self.closed:
            raise ValueError("flush of closed file")
        while self._write_buf:
            try:
                n = self.raw.write(self._write_buf)
            except BlockingIOError:
                raise RuntimeError("self.raw should implement RawIOBase: it "
                                   "should not raise BlockingIOError")
            except IOError as e:
                if e.errno != EINTR:
                    raise
                continue
            if n is None:
                raise BlockingIOError(
                    errno.EAGAIN,
                    "write could not complete without blocking", 0)
            if n > len(self._write_buf) or n < 0:
                raise IOError("write() returned incorrect number of bytes")
            del self._write_buf[:n] 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:_pyio.py

示例14: mocked_select_module

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def mocked_select_module(self):
        """Mocks the select.select() call to raise EINTR for first call"""
        old_select = select.select

        class MockSelect:
            def __init__(self):
                self.called = 0

            def __call__(self, *args):
                self.called += 1
                if self.called == 1:
                    # raise the exception on first call
                    raise select.error(errno.EINTR, os.strerror(errno.EINTR))
                else:
                    # Return real select value for consecutive calls
                    return old_select(*args)

        select.select = MockSelect()
        try:
            yield select.select
        finally:
            select.select = old_select 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_socketserver.py

示例15: test_communicate_eintr

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINTR [as 别名]
def test_communicate_eintr(self):
        # Issue #12493: communicate() should handle EINTR
        def handler(signum, frame):
            pass
        old_handler = signal.signal(signal.SIGALRM, handler)
        self.addCleanup(signal.signal, signal.SIGALRM, old_handler)

        # the process is running for 2 seconds
        args = [sys.executable, "-c", 'import time; time.sleep(2)']
        for stream in ('stdout', 'stderr'):
            kw = {stream: subprocess.PIPE}
            with subprocess.Popen(args, **kw) as process:
                signal.alarm(1)
                try:
                    # communicate() will be interrupted by SIGALRM
                    process.communicate()
                finally:
                    signal.alarm(0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_subprocess.py


注:本文中的errno.EINTR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。