本文整理汇总了Python中errno.EAGAIN属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EAGAIN属性的具体用法?Python errno.EAGAIN怎么用?Python errno.EAGAIN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EAGAIN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _receive_device
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [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
示例2: _raise_timeout
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
# See the above comment about EAGAIN in Python 3. In Python 2 we have
# to specifically catch it and throw the timeout error
if hasattr(err, 'errno') and err.errno in _blocking_errnos:
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
# Catch possible read timeouts thrown as SSL errors. If not the
# case, rethrow the original. We need to do this because of:
# http://bugs.python.org/issue10272
if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python 2.6
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
示例3: _flush_unlocked
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [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 InterruptedError:
continue
except BlockingIOError:
raise RuntimeError("self.raw should implement RawIOBase: it "
"should not raise BlockingIOError")
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]
示例4: _raise_timeout
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
# See the above comment about EAGAIN in Python 3. In Python 2 we have
# to specifically catch it and throw the timeout error
if hasattr(err, 'errno') and err.errno in _blocking_errnos:
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
# Catch possible read timeouts thrown as SSL errors. If not the
# case, rethrow the original. We need to do this because of:
# http://bugs.python.org/issue10272
if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python < 2.7.4
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
示例5: _send_buffer
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _send_buffer(self, buff, target, send_all=False):
size = len(buff)
tosend = size
already_sent = 0
while tosend > 0:
try:
# i should be able to send a bytearray
sent = target.send(buff[already_sent:])
if sent == 0:
raise RuntimeError('socket connection broken')
already_sent += sent
tosend -= sent
except socket.error as e:
# if full buffers then wait for them to drain and try again
if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
if send_all:
continue
return buff[already_sent:]
else:
raise exception.SocketException(str(e))
return None
示例6: _raise_timeout
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
raise ReadTimeoutError(
self, url, "Read timed out. (read timeout=%s)" % timeout_value
)
# See the above comment about EAGAIN in Python 3. In Python 2 we have
# to specifically catch it and throw the timeout error
if hasattr(err, "errno") and err.errno in _blocking_errnos:
raise ReadTimeoutError(
self, url, "Read timed out. (read timeout=%s)" % timeout_value
)
# Catch possible read timeouts thrown as SSL errors. If not the
# case, rethrow the original. We need to do this because of:
# http://bugs.python.org/issue10272
if "timed out" in str(err) or "did not complete (read)" in str(
err
): # Python < 2.7.4
raise ReadTimeoutError(
self, url, "Read timed out. (read timeout=%s)" % timeout_value
)
示例7: recvfrom
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def recvfrom(self, bufsize, flags=0):
if self.type != socket.SOCK_DGRAM:
return _BaseSocket.recvfrom(self, bufsize, flags)
if not self._proxyconn:
self.bind(("", 0))
buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
buf.seek(+2, SEEK_CUR)
frag = buf.read(1)
if ord(frag):
raise NotImplementedError("Received UDP packet fragment")
fromhost, fromport = self._read_SOCKS5_address(buf)
peerhost, peerport = self.proxy_peername
filterhost = socket.inet_pton(self.family, peerhost).strip(b"\x00")
filterhost = filterhost and fromhost != peerhost
if filterhost or peerport not in (0, fromport):
raise socket.error(EAGAIN, "Packet filtered")
return (buf.read(), (fromhost, fromport))
示例8: test_send_command_unreliable_network
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [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"""
)
示例9: recvfrom
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def recvfrom(self, bufsize, flags=0):
if self.type != socket.SOCK_DGRAM:
return _BaseSocket.recvfrom(self, bufsize, flags)
if not self._proxyconn:
self.bind(("", 0))
buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
buf.seek(+2, SEEK_CUR)
frag = buf.read(1)
if ord(frag):
raise NotImplementedError("Received UDP packet fragment")
fromhost, fromport = self._read_SOCKS5_address(buf)
if self.proxy_peername:
peerhost, peerport = self.proxy_peername
if fromhost != peerhost or peerport not in (0, fromport):
raise socket.error(EAGAIN, "Packet filtered")
return (buf.read(), (fromhost, fromport))
示例10: _sendBuffer
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _sendBuffer(self, buff):
size = len(buff)
tosend = size
already_sent = 0
while tosend > 0:
try:
# i should be able to send a bytearray
sent = self.client.send(buff[already_sent:])
if sent == 0:
raise RuntimeError('socket connection broken')
already_sent += sent
tosend -= sent
except socket.error as e:
# if we have full buffers then wait for them to drain and try
# again
if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
return buff[already_sent:]
else:
raise e
return None
示例11: sleep
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [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()
示例12: _setup_connection
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _setup_connection(self, dstaddr, timeout=None):
port = randint(10000, 60000)
af, socktype, proto, _canonname, _sa = socket.getaddrinfo(dstaddr, port, socket.AF_INET, socket.SOCK_DGRAM)[0]
s = socket.socket(af, socktype, proto)
has_bind = 1
for _i in range(0, 10):
# We try to bind to a port for 10 tries
try:
s.bind((INADDR_ANY, randint(10000, 60000)))
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
has_bind = 1
except socket.error:
pass
if not has_bind:
raise NetBIOSError, ('Cannot bind to a good UDP port', ERRCLASS_OS, errno.EAGAIN)
self.__sock = s
示例13: non_polling_read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [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])
示例14: _receive
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _receive(self):
"""Receive any incoming socket data.
If an error is thrown, handle it and return an empty string.
:return: data_in
:rtype: bytes
"""
data_in = EMPTY_BUFFER
try:
if not self.socket:
raise socket.error('connection/socket error')
data_in = self._read_from_socket()
except socket.timeout:
pass
except (IOError, OSError) as why:
if why.args[0] not in (EWOULDBLOCK, EAGAIN):
self._exceptions.append(AMQPConnectionError(why))
self._running.clear()
return data_in
示例15: read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def read(self, size):
while len(self.buffer) < size:
self.ensure_connection()
try:
packet = self.socket.recv(self.buffer_size)
except socket.error as error:
if error.errno in (EDEADLK, EAGAIN, EWOULDBLOCK):
gevent.sleep()
continue
six.raise_from(NSQSocketError(*error.args), error)
if not packet:
self.close()
self.buffer += packet
data = self.buffer[:size]
self.buffer = self.buffer[size:]
return data