本文整理匯總了Python中select.error方法的典型用法代碼示例。如果您正苦於以下問題:Python select.error方法的具體用法?Python select.error怎麽用?Python select.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類select
的用法示例。
在下文中一共展示了select.error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def send(self, channel_type, message, additional_data):
if channel_type == common.CONTROL_CHANNEL_BYTE:
transformed_message = self.transform(self.encryption, common.CONTROL_CHANNEL_BYTE+message, 1)
else:
transformed_message = self.transform(self.encryption, common.DATA_CHANNEL_BYTE+message, 1)
common.internal_print("{0} sent: {1}".format(self.module_short, len(transformed_message)), 0, self.verbosity, common.DEBUG)
# WORKAROUND?!
# Windows: It looks like when the buffer fills up the OS does not do
# congestion control, instead throws and exception/returns with
# WSAEWOULDBLOCK which means that we need to try it again later.
# So we sleep 100ms and hope that the buffer has more space for us.
# If it does then it sends the data, otherwise tries it in an infinite
# loop...
while True:
try:
return self.comms_socket.send(struct.pack(">H", len(transformed_message))+transformed_message)
except socket.error as se:
if se.args[0] == 10035: # WSAEWOULDBLOCK
time.sleep(0.1)
pass
else:
raise
示例2: check
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def check(self):
try:
common.internal_print("Checking module on server: {0}".format(self.get_module_name()))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.settimeout(3)
server_socket.connect((self.config.get("Global", "remoteserverip"), int(self.config.get(self.get_module_configname(), "serverport"))))
client_fake_thread = TCP_generic_thread(0, 0, None, None, server_socket, None, self.authentication, self.encryption_module, self.verbosity, self.config, self.get_module_name())
client_fake_thread.do_check()
client_fake_thread.communication(True)
self.cleanup(server_socket)
except socket.timeout:
common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1)
self.cleanup(server_socket)
except socket.error as exception:
if exception.args[0] == 111:
common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1)
else:
common.internal_print("Connection error: {0}".format(self.get_module_name()), -1)
self.cleanup(server_socket)
return
示例3: connect
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def connect(self):
try:
common.internal_print("Starting client: {0}".format(self.get_module_name()))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.server_tuple = (self.config.get("Global", "remoteserverip"), int(self.config.get(self.get_module_configname(), "serverport")))
self.comms_socket = server_socket
self.serverorclient = 0
self.authenticated = False
self.do_hello()
self.communication(False)
except KeyboardInterrupt:
self.do_logoff()
self.cleanup()
raise
except socket.error:
self.cleanup()
raise
self.cleanup()
return
示例4: check
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def check(self):
try:
common.internal_print("Checking module on server: {0}".format(self.get_module_name()))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.server_tuple = (self.config.get("Global", "remoteserverip"), int(self.config.get(self.get_module_configname(), "serverport")))
self.comms_socket = server_socket
self.serverorclient = 0
self.authenticated = False
self.do_check()
self.communication(True)
except KeyboardInterrupt:
self.cleanup()
raise
except socket.timeout:
common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1)
except socket.error:
self.cleanup()
raise
self.cleanup()
return
示例5: listen
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def listen(server, on_read):
sock, addr = server.accept()
timeout = 10
try:
read_ready, _, _ = select.select([sock], [], [], timeout)
while len(read_ready):
data = sock.recv(8192)
if on_read(sock, data):
read_ready, _, _ = select.select([sock], [], [], 0)
else:
read_ready = []
except (socket.error, select.error, OSError, ValueError):
pass
try:
sock.shutdown(socket.SHUT_RDWR)
except (socket.error, OSError, ValueError):
pass
sock.close()
示例6: proxy
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def proxy(src, dst, callback=None):
timeout = 10
try:
read_ready, _, _ = select.select([src], [], [], timeout)
while len(read_ready):
if callback:
callback(src, dst)
else:
dst.send(src.recv(8192))
read_ready, _, _ = select.select([src], [], [], timeout)
except (socket.error, select.error, OSError, ValueError):
pass
try:
src.shutdown(socket.SHUT_RDWR)
except (socket.error, OSError, ValueError):
pass
src.close()
try:
dst.shutdown(socket.SHUT_RDWR)
except (socket.error, OSError, ValueError):
pass
dst.close()
示例7: _internal_poll
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
_WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD):
"""Check if child process has terminated. Returns returncode
attribute.
This method is called by __del__, so it cannot reference anything
outside of the local scope (nor can any methods it calls).
"""
if self.returncode is None:
try:
pid, sts = _waitpid(self.pid, _WNOHANG)
if pid == self.pid:
self._handle_exitstatus(sts)
except _os_error as e:
if _deadstate is not None:
self.returncode = _deadstate
elif e.errno == _ECHILD:
# This happens if SIGCLD is set to be ignored or
# waiting for child processes has otherwise been
# disabled for our process. This child is dead, we
# can't get the status.
# http://bugs.python.org/issue15756
self.returncode = 0
return self.returncode
示例8: _retry_on_intr
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [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
示例9: _send_buffer
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [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
示例10: _read_messages
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def _read_messages(self):
while self.connected:
try:
r, w, e = select.select([self.sock], [], [])
except select.error:
break
if r and self.connected:
with self.cLock:
data = self.recv()
message = json.loads(data)
# If id is present -> notifies main thread to return this message as a reply
# Otherwise puts message into events queue so it will be dispatched as event
if 'id' in message:
self.replies[message['id']] = message
self.cLock.notify()
else:
self.events.put(message)
示例11: unregister
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def unregister(self, fileobj):
"""Unregisters a file object from being monitored."""
try:
key = self._fd_to_key.pop(self._fileobj_lookup(fileobj))
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj))
# Getting the fileno of a closed socket on Windows errors with EBADF.
except socket.error as e: # Platform-specific: Windows.
if e.errno != errno.EBADF:
raise
else:
for key in self._fd_to_key.values():
if key.fileobj is fileobj:
self._fd_to_key.pop(key.fd)
break
else:
raise KeyError("{!r} is not registered".format(fileobj))
return key
示例12: unregister
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def unregister(self, fileobj):
""" Unregister a file object from being monitored. """
try:
key = self._fd_to_key.pop(self._fileobj_lookup(fileobj))
except KeyError:
raise KeyError("{0!r} is not registered".format(fileobj))
# Getting the fileno of a closed socket on Windows errors with EBADF.
except socket.error as e: # Platform-specific: Windows.
if e.errno != errno.EBADF:
raise
else:
for key in self._fd_to_key.values():
if key.fileobj is fileobj:
self._fd_to_key.pop(key.fd)
break
else:
raise KeyError("{0!r} is not registered".format(fileobj))
return key
示例13: wrap_error
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [as 別名]
def wrap_error(func, *args, **kw):
"""
Wrap socket.error, IOError, OSError, select.error to raise new specialized
exceptions of Python 3.3 like InterruptedError (PEP 3151).
"""
try:
return func(*args, **kw)
except (socket.error, IOError, OSError) as exc:
if hasattr(exc, 'winerror'):
_wrap_error(exc, _MAP_ERRNO, exc.winerror)
# _MAP_ERRNO does not contain all Windows errors.
# For some errors like "file not found", exc.errno should
# be used (ex: ENOENT).
_wrap_error(exc, _MAP_ERRNO, exc.errno)
raise
except select.error as exc:
if exc.args:
_wrap_error(exc, _MAP_ERRNO, exc.args[0])
raise
示例14: wait
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [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
示例15: sleep
# 需要導入模塊: import select [as 別名]
# 或者: from select import error [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()