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


Python select.error方法代码示例

本文整理汇总了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 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:26,代码来源:TCP_generic.py

示例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 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:26,代码来源:TCP_generic.py

示例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 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:25,代码来源:UDP_generic.py

示例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 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:27,代码来源:UDP_generic.py

示例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() 
开发者ID:wbond,项目名称:oscrypto,代码行数:21,代码来源:_socket_server.py

示例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() 
开发者ID:wbond,项目名称:oscrypto,代码行数:24,代码来源:_socket_proxy.py

示例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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:subprocess.py

示例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 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:23,代码来源:wait.py

示例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 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:websocketproxy.py

示例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) 
开发者ID:asyne,项目名称:cproto,代码行数:21,代码来源:websocket.py

示例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 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:21,代码来源:ssl_wrap_util.py

示例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 
开发者ID:getavalon,项目名称:core,代码行数:21,代码来源:selectors.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:_compat.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:sync.py

示例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() 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:arbiter.py


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