本文整理汇总了Python中selectors._fileobj_to_fd方法的典型用法代码示例。如果您正苦于以下问题:Python selectors._fileobj_to_fd方法的具体用法?Python selectors._fileobj_to_fd怎么用?Python selectors._fileobj_to_fd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selectors
的用法示例。
在下文中一共展示了selectors._fileobj_to_fd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ensure_fd_no_transport
# 需要导入模块: import selectors [as 别名]
# 或者: from selectors import _fileobj_to_fd [as 别名]
def _ensure_fd_no_transport(self, fd):
fileno = fd
if not isinstance(fileno, int):
try:
fileno = int(fileno.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches selectors._fileobj_to_fd function.
raise ValueError(f"Invalid file object: {fd!r}") from None
try:
transport = self._transports[fileno]
except KeyError:
pass
else:
if not transport.is_closing():
raise RuntimeError(
f'File descriptor {fd!r} is used by transport '
f'{transport!r}')
示例2: _ensure_fd_no_transport
# 需要导入模块: import selectors [as 别名]
# 或者: from selectors import _fileobj_to_fd [as 别名]
def _ensure_fd_no_transport(self, fd):
if not isinstance(fd, int):
try:
fd = int(fd.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches selectors._fileobj_to_fd function.
raise ValueError("Invalid file object: "
"{!r}".format(fd)) from None
try:
transport = self._transports[fd]
except KeyError:
pass
else:
raise RuntimeError(
'File descriptor {!r} is used by transport {!r}'.format(
fd, transport))