本文整理匯總了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))