gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1088 lines
77KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="select — Waiting for I/O completion" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/select.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module provides access to the select() and poll() functions available in most operating systems, devpoll() available on Solaris and derivatives, epoll() available on Linux 2.5+ and kqueue() av..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="This module provides access to the select() and poll() functions available in most operating systems, devpoll() available on Solaris and derivatives, epoll() available on Linux 2.5+ and kqueue() av..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>select — Waiting for I/O completion &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="selectors — High-level I/O multiplexing" href="selectors.html" />
  33. <link rel="prev" title="ssl — TLS/SSL wrapper for socket objects" href="ssl.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/select.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code> — Waiting for I/O completion</a><ul>
  86. <li><a class="reference internal" href="#dev-poll-polling-objects"><code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> Polling Objects</a></li>
  87. <li><a class="reference internal" href="#edge-and-level-trigger-polling-epoll-objects">Edge and Level Trigger Polling (epoll) Objects</a></li>
  88. <li><a class="reference internal" href="#polling-objects">Polling Objects</a></li>
  89. <li><a class="reference internal" href="#kqueue-objects">Kqueue Objects</a></li>
  90. <li><a class="reference internal" href="#kevent-objects">Kevent Objects</a></li>
  91. </ul>
  92. </li>
  93. </ul>
  94. </div>
  95. <div>
  96. <h4>Previous topic</h4>
  97. <p class="topless"><a href="ssl.html"
  98. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code> — TLS/SSL wrapper for socket objects</a></p>
  99. </div>
  100. <div>
  101. <h4>Next topic</h4>
  102. <p class="topless"><a href="selectors.html"
  103. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code> — High-level I/O multiplexing</a></p>
  104. </div>
  105. <div role="note" aria-label="source link">
  106. <h3>This Page</h3>
  107. <ul class="this-page-menu">
  108. <li><a href="../bugs.html">Report a Bug</a></li>
  109. <li>
  110. <a href="https://github.com/python/cpython/blob/main/Doc/library/select.rst"
  111. rel="nofollow">Show Source
  112. </a>
  113. </li>
  114. </ul>
  115. </div>
  116. </nav>
  117. </div>
  118. </div>
  119. <div class="related" role="navigation" aria-label="related navigation">
  120. <h3>Navigation</h3>
  121. <ul>
  122. <li class="right" style="margin-right: 10px">
  123. <a href="../genindex.html" title="General Index"
  124. accesskey="I">index</a></li>
  125. <li class="right" >
  126. <a href="../py-modindex.html" title="Python Module Index"
  127. >modules</a> |</li>
  128. <li class="right" >
  129. <a href="selectors.html" title="selectors — High-level I/O multiplexing"
  130. accesskey="N">next</a> |</li>
  131. <li class="right" >
  132. <a href="ssl.html" title="ssl — TLS/SSL wrapper for socket objects"
  133. accesskey="P">previous</a> |</li>
  134. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  135. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  136. <li class="switchers">
  137. <div class="language_switcher_placeholder"></div>
  138. <div class="version_switcher_placeholder"></div>
  139. </li>
  140. <li>
  141. </li>
  142. <li id="cpython-language-and-version">
  143. <a href="../index.html">3.12.3 Documentation</a> &#187;
  144. </li>
  145. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  146. <li class="nav-item nav-item-2"><a href="ipc.html" accesskey="U">Networking and Interprocess Communication</a> &#187;</li>
  147. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code> — Waiting for I/O completion</a></li>
  148. <li class="right">
  149. <div class="inline-search" role="search">
  150. <form class="inline-search" action="../search.html" method="get">
  151. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  152. <input type="submit" value="Go" />
  153. </form>
  154. </div>
  155. |
  156. </li>
  157. <li class="right">
  158. <label class="theme-selector-label">
  159. Theme
  160. <select class="theme-selector" oninput="activateTheme(this.value)">
  161. <option value="auto" selected>Auto</option>
  162. <option value="light">Light</option>
  163. <option value="dark">Dark</option>
  164. </select>
  165. </label> |</li>
  166. </ul>
  167. </div>
  168. <div class="document">
  169. <div class="documentwrapper">
  170. <div class="bodywrapper">
  171. <div class="body" role="main">
  172. <section id="module-select">
  173. <span id="select-waiting-for-i-o-completion"></span><h1><a class="reference internal" href="#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> — Waiting for I/O completion<a class="headerlink" href="#module-select" title="Link to this heading">¶</a></h1>
  174. <hr class="docutils" />
  175. <p>This module provides access to the <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code> functions
  176. available in most operating systems, <code class="xref c c-func docutils literal notranslate"><span class="pre">devpoll()</span></code> available on
  177. Solaris and derivatives, <code class="xref c c-func docutils literal notranslate"><span class="pre">epoll()</span></code> available on Linux 2.5+ and
  178. <code class="xref c c-func docutils literal notranslate"><span class="pre">kqueue()</span></code> available on most BSD.
  179. Note that on Windows, it only works for sockets; on other operating systems,
  180. it also works for other file types (in particular, on Unix, it works on pipes).
  181. It cannot be used on regular files to determine whether a file has grown since
  182. it was last read.</p>
  183. <div class="admonition note">
  184. <p class="admonition-title">Note</p>
  185. <p>The <a class="reference internal" href="selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a> module allows high-level and efficient I/O
  186. multiplexing, built upon the <a class="reference internal" href="#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> module primitives. Users are
  187. encouraged to use the <a class="reference internal" href="selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a> module instead, unless they want
  188. precise control over the OS-level primitives used.</p>
  189. </div>
  190. <div class="availability docutils container">
  191. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p>
  192. <p>This module does not work or is not available on WebAssembly platforms
  193. <code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> and <code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code>. See
  194. <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>
  195. </div>
  196. <p>The module defines the following:</p>
  197. <dl class="py exception">
  198. <dt class="sig sig-object py" id="select.error">
  199. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">error</span></span><a class="headerlink" href="#select.error" title="Link to this definition">¶</a></dt>
  200. <dd><p>A deprecated alias of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  201. <div class="versionchanged">
  202. <p><span class="versionmodified changed">Changed in version 3.3: </span>Following <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a>, this class was made an alias of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  203. </div>
  204. </dd></dl>
  205. <dl class="py function">
  206. <dt class="sig sig-object py" id="select.devpoll">
  207. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">devpoll</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll" title="Link to this definition">¶</a></dt>
  208. <dd><p>(Only supported on Solaris and derivatives.) Returns a <code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code>
  209. polling object; see section <a class="reference internal" href="#devpoll-objects"><span class="std std-ref">/dev/poll Polling Objects</span></a> below for the
  210. methods supported by devpoll objects.</p>
  211. <p><code class="xref c c-func docutils literal notranslate"><span class="pre">devpoll()</span></code> objects are linked to the number of file
  212. descriptors allowed at the time of instantiation. If your program
  213. reduces this value, <code class="xref c c-func docutils literal notranslate"><span class="pre">devpoll()</span></code> will fail. If your program
  214. increases this value, <code class="xref c c-func docutils literal notranslate"><span class="pre">devpoll()</span></code> may return an
  215. incomplete list of active file descriptors.</p>
  216. <p>The new file descriptor is <a class="reference internal" href="os.html#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
  217. <div class="versionadded">
  218. <p><span class="versionmodified added">New in version 3.3.</span></p>
  219. </div>
  220. <div class="versionchanged">
  221. <p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
  222. </div>
  223. </dd></dl>
  224. <dl class="py function">
  225. <dt class="sig sig-object py" id="select.epoll">
  226. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">epoll</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sizehint</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll" title="Link to this definition">¶</a></dt>
  227. <dd><p>(Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
  228. which can be used as Edge or Level Triggered interface for I/O
  229. events.</p>
  230. <p><em>sizehint</em> informs epoll about the expected number of events to be
  231. registered. It must be positive, or <code class="docutils literal notranslate"><span class="pre">-1</span></code> to use the default. It is only
  232. used on older systems where <code class="xref c c-func docutils literal notranslate"><span class="pre">epoll_create1()</span></code> is not available;
  233. otherwise it has no effect (though its value is still checked).</p>
  234. <p><em>flags</em> is deprecated and completely ignored. However, when supplied, its
  235. value must be <code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">select.EPOLL_CLOEXEC</span></code>, otherwise <code class="docutils literal notranslate"><span class="pre">OSError</span></code> is
  236. raised.</p>
  237. <p>See the <a class="reference internal" href="#epoll-objects"><span class="std std-ref">Edge and Level Trigger Polling (epoll) Objects</span></a> section below for the methods supported by
  238. epolling objects.</p>
  239. <p><code class="docutils literal notranslate"><span class="pre">epoll</span></code> objects support the context management protocol: when used in a
  240. <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement, the new file descriptor is automatically closed
  241. at the end of the block.</p>
  242. <p>The new file descriptor is <a class="reference internal" href="os.html#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
  243. <div class="versionchanged">
  244. <p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>flags</em> parameter.</p>
  245. </div>
  246. <div class="versionchanged">
  247. <p><span class="versionmodified changed">Changed in version 3.4: </span>Support for the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement was added.
  248. The new file descriptor is now non-inheritable.</p>
  249. </div>
  250. <div class="deprecated">
  251. <p><span class="versionmodified deprecated">Deprecated since version 3.4: </span>The <em>flags</em> parameter. <code class="docutils literal notranslate"><span class="pre">select.EPOLL_CLOEXEC</span></code> is used by default now.
  252. Use <a class="reference internal" href="os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_inheritable()</span></code></a> to make the file descriptor inheritable.</p>
  253. </div>
  254. </dd></dl>
  255. <dl class="py function">
  256. <dt class="sig sig-object py" id="select.poll">
  257. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">poll</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.poll" title="Link to this definition">¶</a></dt>
  258. <dd><p>(Not supported by all operating systems.) Returns a polling object, which
  259. supports registering and unregistering file descriptors, and then polling them
  260. for I/O events; see section <a class="reference internal" href="#poll-objects"><span class="std std-ref">Polling Objects</span></a> below for the methods supported
  261. by polling objects.</p>
  262. </dd></dl>
  263. <dl class="py function">
  264. <dt class="sig sig-object py" id="select.kqueue">
  265. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">kqueue</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.kqueue" title="Link to this definition">¶</a></dt>
  266. <dd><p>(Only supported on BSD.) Returns a kernel queue object; see section
  267. <a class="reference internal" href="#kqueue-objects"><span class="std std-ref">Kqueue Objects</span></a> below for the methods supported by kqueue objects.</p>
  268. <p>The new file descriptor is <a class="reference internal" href="os.html#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
  269. <div class="versionchanged">
  270. <p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
  271. </div>
  272. </dd></dl>
  273. <dl class="py function">
  274. <dt class="sig sig-object py" id="select.kevent">
  275. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">kevent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ident</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KQ_FILTER_READ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KQ_EV_ADD</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fflags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">udata</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.kevent" title="Link to this definition">¶</a></dt>
  276. <dd><p>(Only supported on BSD.) Returns a kernel event object; see section
  277. <a class="reference internal" href="#kevent-objects"><span class="std std-ref">Kevent Objects</span></a> below for the methods supported by kevent objects.</p>
  278. </dd></dl>
  279. <dl class="py function">
  280. <dt class="sig sig-object py" id="select.select">
  281. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">select</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rlist</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wlist</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xlist</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.select" title="Link to this definition">¶</a></dt>
  282. <dd><p>This is a straightforward interface to the Unix <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> system call.
  283. The first three arguments are iterables of ‘waitable objects’: either
  284. integers representing file descriptors or objects with a parameterless method
  285. named <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> returning such an integer:</p>
  286. <ul class="simple">
  287. <li><p><em>rlist</em>: wait until ready for reading</p></li>
  288. <li><p><em>wlist</em>: wait until ready for writing</p></li>
  289. <li><p><em>xlist</em>: wait for an “exceptional condition” (see the manual page for what
  290. your system considers such a condition)</p></li>
  291. </ul>
  292. <p>Empty iterables are allowed, but acceptance of three empty iterables is
  293. platform-dependent. (It is known to work on Unix but not on Windows.) The
  294. optional <em>timeout</em> argument specifies a time-out as a floating point number
  295. in seconds. When the <em>timeout</em> argument is omitted the function blocks until
  296. at least one file descriptor is ready. A time-out value of zero specifies a
  297. poll and never blocks.</p>
  298. <p>The return value is a triple of lists of objects that are ready: subsets of the
  299. first three arguments. When the time-out is reached without a file descriptor
  300. becoming ready, three empty lists are returned.</p>
  301. <p id="index-1">Among the acceptable object types in the iterables are Python <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file
  302. objects</span></a> (e.g. <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, or objects returned by
  303. <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or <a class="reference internal" href="os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a>), socket objects returned by
  304. <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.socket()</span></code></a>. You may also define a <em class="dfn">wrapper</em> class yourself,
  305. as long as it has an appropriate <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method (that
  306. really returns a file descriptor, not just a random integer).</p>
  307. <div class="admonition note">
  308. <p class="admonition-title">Note</p>
  309. <p id="index-2">File objects on Windows are not acceptable, but sockets are. On Windows,
  310. the underlying <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> function is provided by the WinSock
  311. library, and does not handle file descriptors that don’t originate from
  312. WinSock.</p>
  313. </div>
  314. <div class="versionchanged">
  315. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now retried with a recomputed timeout when interrupted by
  316. a signal, except if the signal handler raises an exception (see
  317. <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising
  318. <a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p>
  319. </div>
  320. </dd></dl>
  321. <dl class="py attribute">
  322. <dt class="sig sig-object py" id="select.PIPE_BUF">
  323. <span class="sig-prename descclassname"><span class="pre">select.</span></span><span class="sig-name descname"><span class="pre">PIPE_BUF</span></span><a class="headerlink" href="#select.PIPE_BUF" title="Link to this definition">¶</a></dt>
  324. <dd><p>The minimum number of bytes which can be written without blocking to a pipe
  325. when the pipe has been reported as ready for writing by <a class="reference internal" href="#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a>,
  326. <code class="xref py py-func docutils literal notranslate"><span class="pre">poll()</span></code> or another interface in this module. This doesn’t apply
  327. to other kind of file-like objects such as sockets.</p>
  328. <p>This value is guaranteed by POSIX to be at least 512.</p>
  329. <div class="availability docutils container">
  330. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix</p>
  331. </div>
  332. <div class="versionadded">
  333. <p><span class="versionmodified added">New in version 3.2.</span></p>
  334. </div>
  335. </dd></dl>
  336. <section id="dev-poll-polling-objects">
  337. <span id="devpoll-objects"></span><h2><code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> Polling Objects<a class="headerlink" href="#dev-poll-polling-objects" title="Link to this heading">¶</a></h2>
  338. <p>Solaris and derivatives have <code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code>. While <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> is
  339. <em>O</em>(<em>highest file descriptor</em>) and <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code> is <em>O</em>(<em>number of file
  340. descriptors</em>), <code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> is <em>O</em>(<em>active file descriptors</em>).</p>
  341. <p><code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> behaviour is very close to the standard <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code>
  342. object.</p>
  343. <dl class="py method">
  344. <dt class="sig sig-object py" id="select.devpoll.close">
  345. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.close" title="Link to this definition">¶</a></dt>
  346. <dd><p>Close the file descriptor of the polling object.</p>
  347. <div class="versionadded">
  348. <p><span class="versionmodified added">New in version 3.4.</span></p>
  349. </div>
  350. </dd></dl>
  351. <dl class="py attribute">
  352. <dt class="sig sig-object py" id="select.devpoll.closed">
  353. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#select.devpoll.closed" title="Link to this definition">¶</a></dt>
  354. <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the polling object is closed.</p>
  355. <div class="versionadded">
  356. <p><span class="versionmodified added">New in version 3.4.</span></p>
  357. </div>
  358. </dd></dl>
  359. <dl class="py method">
  360. <dt class="sig sig-object py" id="select.devpoll.fileno">
  361. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">fileno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.fileno" title="Link to this definition">¶</a></dt>
  362. <dd><p>Return the file descriptor number of the polling object.</p>
  363. <div class="versionadded">
  364. <p><span class="versionmodified added">New in version 3.4.</span></p>
  365. </div>
  366. </dd></dl>
  367. <dl class="py method">
  368. <dt class="sig sig-object py" id="select.devpoll.register">
  369. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.register" title="Link to this definition">¶</a></dt>
  370. <dd><p>Register a file descriptor with the polling object. Future calls to the
  371. <a class="reference internal" href="#select.poll" title="select.poll"><code class="xref py py-meth docutils literal notranslate"><span class="pre">poll()</span></code></a> method will then check whether the file descriptor has any
  372. pending I/O events. <em>fd</em> can be either an integer, or an object with a
  373. <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method that returns an integer. File objects
  374. implement <code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code>, so they can also be used as the argument.</p>
  375. <p><em>eventmask</em> is an optional bitmask describing the type of events you want to
  376. check for. The constants are the same that with <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code>
  377. object. The default value is a combination of the constants <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLIN</span></code>,
  378. <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLPRI</span></code>, and <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLOUT</span></code>.</p>
  379. <div class="admonition warning">
  380. <p class="admonition-title">Warning</p>
  381. <p>Registering a file descriptor that’s already registered is not an
  382. error, but the result is undefined. The appropriate action is to
  383. unregister or modify it first. This is an important difference
  384. compared with <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code>.</p>
  385. </div>
  386. </dd></dl>
  387. <dl class="py method">
  388. <dt class="sig sig-object py" id="select.devpoll.modify">
  389. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">modify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.modify" title="Link to this definition">¶</a></dt>
  390. <dd><p>This method does an <a class="reference internal" href="#select.devpoll.unregister" title="select.devpoll.unregister"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unregister()</span></code></a> followed by a
  391. <a class="reference internal" href="#select.devpoll.register" title="select.devpoll.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register()</span></code></a>. It is (a bit) more efficient that doing the same
  392. explicitly.</p>
  393. </dd></dl>
  394. <dl class="py method">
  395. <dt class="sig sig-object py" id="select.devpoll.unregister">
  396. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">unregister</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.unregister" title="Link to this definition">¶</a></dt>
  397. <dd><p>Remove a file descriptor being tracked by a polling object. Just like the
  398. <a class="reference internal" href="#select.devpoll.register" title="select.devpoll.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register()</span></code></a> method, <em>fd</em> can be an integer or an object with a
  399. <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method that returns an integer.</p>
  400. <p>Attempting to remove a file descriptor that was never registered is
  401. safely ignored.</p>
  402. </dd></dl>
  403. <dl class="py method">
  404. <dt class="sig sig-object py" id="select.devpoll.poll">
  405. <span class="sig-prename descclassname"><span class="pre">devpoll.</span></span><span class="sig-name descname"><span class="pre">poll</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.devpoll.poll" title="Link to this definition">¶</a></dt>
  406. <dd><p>Polls the set of registered file descriptors, and returns a possibly empty list
  407. containing <code class="docutils literal notranslate"><span class="pre">(fd,</span> <span class="pre">event)</span></code> 2-tuples for the descriptors that have events or
  408. errors to report. <em>fd</em> is the file descriptor, and <em>event</em> is a bitmask with
  409. bits set for the reported events for that descriptor — <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLIN</span></code> for
  410. waiting input, <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLOUT</span></code> to indicate that the descriptor can be written
  411. to, and so forth. An empty list indicates that the call timed out and no file
  412. descriptors had any events to report. If <em>timeout</em> is given, it specifies the
  413. length of time in milliseconds which the system will wait for events before
  414. returning. If <em>timeout</em> is omitted, -1, or <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, the call will
  415. block until there is an event for this poll object.</p>
  416. <div class="versionchanged">
  417. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now retried with a recomputed timeout when interrupted by
  418. a signal, except if the signal handler raises an exception (see
  419. <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising
  420. <a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p>
  421. </div>
  422. </dd></dl>
  423. </section>
  424. <section id="edge-and-level-trigger-polling-epoll-objects">
  425. <span id="epoll-objects"></span><h2>Edge and Level Trigger Polling (epoll) Objects<a class="headerlink" href="#edge-and-level-trigger-polling-epoll-objects" title="Link to this heading">¶</a></h2>
  426. <blockquote>
  427. <div><p><a class="reference external" href="https://linux.die.net/man/4/epoll">https://linux.die.net/man/4/epoll</a></p>
  428. <p><em>eventmask</em></p>
  429. <table class="docutils align-default">
  430. <thead>
  431. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  432. <th class="head"><p>Meaning</p></th>
  433. </tr>
  434. </thead>
  435. <tbody>
  436. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLIN</span></code></p></td>
  437. <td><p>Available for read</p></td>
  438. </tr>
  439. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLOUT</span></code></p></td>
  440. <td><p>Available for write</p></td>
  441. </tr>
  442. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLPRI</span></code></p></td>
  443. <td><p>Urgent data for read</p></td>
  444. </tr>
  445. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLERR</span></code></p></td>
  446. <td><p>Error condition happened on the assoc. fd</p></td>
  447. </tr>
  448. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLHUP</span></code></p></td>
  449. <td><p>Hang up happened on the assoc. fd</p></td>
  450. </tr>
  451. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLET</span></code></p></td>
  452. <td><p>Set Edge Trigger behavior, the default is
  453. Level Trigger behavior</p></td>
  454. </tr>
  455. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLONESHOT</span></code></p></td>
  456. <td><p>Set one-shot behavior. After one event is
  457. pulled out, the fd is internally disabled</p></td>
  458. </tr>
  459. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLEXCLUSIVE</span></code></p></td>
  460. <td><p>Wake only one epoll object when the
  461. associated fd has an event. The default (if
  462. this flag is not set) is to wake all epoll
  463. objects polling on a fd.</p></td>
  464. </tr>
  465. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLRDHUP</span></code></p></td>
  466. <td><p>Stream socket peer closed connection or shut
  467. down writing half of connection.</p></td>
  468. </tr>
  469. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLRDNORM</span></code></p></td>
  470. <td><p>Equivalent to <code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLIN</span></code></p></td>
  471. </tr>
  472. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLRDBAND</span></code></p></td>
  473. <td><p>Priority data band can be read.</p></td>
  474. </tr>
  475. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLWRNORM</span></code></p></td>
  476. <td><p>Equivalent to <code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLOUT</span></code></p></td>
  477. </tr>
  478. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLWRBAND</span></code></p></td>
  479. <td><p>Priority data may be written.</p></td>
  480. </tr>
  481. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLMSG</span></code></p></td>
  482. <td><p>Ignored.</p></td>
  483. </tr>
  484. </tbody>
  485. </table>
  486. <div class="versionadded">
  487. <p><span class="versionmodified added">New in version 3.6: </span><code class="xref py py-const docutils literal notranslate"><span class="pre">EPOLLEXCLUSIVE</span></code> was added. It’s only supported by Linux Kernel 4.5
  488. or later.</p>
  489. </div>
  490. </div></blockquote>
  491. <dl class="py method">
  492. <dt class="sig sig-object py" id="select.epoll.close">
  493. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.close" title="Link to this definition">¶</a></dt>
  494. <dd><p>Close the control file descriptor of the epoll object.</p>
  495. </dd></dl>
  496. <dl class="py attribute">
  497. <dt class="sig sig-object py" id="select.epoll.closed">
  498. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#select.epoll.closed" title="Link to this definition">¶</a></dt>
  499. <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the epoll object is closed.</p>
  500. </dd></dl>
  501. <dl class="py method">
  502. <dt class="sig sig-object py" id="select.epoll.fileno">
  503. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">fileno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.fileno" title="Link to this definition">¶</a></dt>
  504. <dd><p>Return the file descriptor number of the control fd.</p>
  505. </dd></dl>
  506. <dl class="py method">
  507. <dt class="sig sig-object py" id="select.epoll.fromfd">
  508. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">fromfd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.fromfd" title="Link to this definition">¶</a></dt>
  509. <dd><p>Create an epoll object from a given file descriptor.</p>
  510. </dd></dl>
  511. <dl class="py method">
  512. <dt class="sig sig-object py" id="select.epoll.register">
  513. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.register" title="Link to this definition">¶</a></dt>
  514. <dd><p>Register a fd descriptor with the epoll object.</p>
  515. </dd></dl>
  516. <dl class="py method">
  517. <dt class="sig sig-object py" id="select.epoll.modify">
  518. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">modify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.modify" title="Link to this definition">¶</a></dt>
  519. <dd><p>Modify a registered file descriptor.</p>
  520. </dd></dl>
  521. <dl class="py method">
  522. <dt class="sig sig-object py" id="select.epoll.unregister">
  523. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">unregister</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.unregister" title="Link to this definition">¶</a></dt>
  524. <dd><p>Remove a registered file descriptor from the epoll object.</p>
  525. <div class="versionchanged">
  526. <p><span class="versionmodified changed">Changed in version 3.9: </span>The method no longer ignores the <a class="reference internal" href="errno.html#errno.EBADF" title="errno.EBADF"><code class="xref py py-data docutils literal notranslate"><span class="pre">EBADF</span></code></a> error.</p>
  527. </div>
  528. </dd></dl>
  529. <dl class="py method">
  530. <dt class="sig sig-object py" id="select.epoll.poll">
  531. <span class="sig-prename descclassname"><span class="pre">epoll.</span></span><span class="sig-name descname"><span class="pre">poll</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxevents</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.epoll.poll" title="Link to this definition">¶</a></dt>
  532. <dd><p>Wait for events. timeout in seconds (float)</p>
  533. <div class="versionchanged">
  534. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now retried with a recomputed timeout when interrupted by
  535. a signal, except if the signal handler raises an exception (see
  536. <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising
  537. <a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p>
  538. </div>
  539. </dd></dl>
  540. </section>
  541. <section id="polling-objects">
  542. <span id="poll-objects"></span><h2>Polling Objects<a class="headerlink" href="#polling-objects" title="Link to this heading">¶</a></h2>
  543. <p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code> system call, supported on most Unix systems, provides better
  544. scalability for network servers that service many, many clients at the same
  545. time. <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code> scales better because the system call only requires listing
  546. the file descriptors of interest, while <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> builds a bitmap, turns
  547. on bits for the fds of interest, and then afterward the whole bitmap has to be
  548. linearly scanned again. <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> is <em>O</em>(<em>highest file descriptor</em>), while
  549. <code class="xref c c-func docutils literal notranslate"><span class="pre">poll()</span></code> is <em>O</em>(<em>number of file descriptors</em>).</p>
  550. <dl class="py method">
  551. <dt class="sig sig-object py" id="select.poll.register">
  552. <span class="sig-prename descclassname"><span class="pre">poll.</span></span><span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.poll.register" title="Link to this definition">¶</a></dt>
  553. <dd><p>Register a file descriptor with the polling object. Future calls to the
  554. <a class="reference internal" href="#select.poll" title="select.poll"><code class="xref py py-meth docutils literal notranslate"><span class="pre">poll()</span></code></a> method will then check whether the file descriptor has any
  555. pending I/O events. <em>fd</em> can be either an integer, or an object with a
  556. <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method that returns an integer. File objects
  557. implement <code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code>, so they can also be used as the argument.</p>
  558. <p><em>eventmask</em> is an optional bitmask describing the type of events you want to
  559. check for, and can be a combination of the constants <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLIN</span></code>,
  560. <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLPRI</span></code>, and <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLOUT</span></code>, described in the table below. If not
  561. specified, the default value used will check for all 3 types of events.</p>
  562. <table class="docutils align-default">
  563. <thead>
  564. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  565. <th class="head"><p>Meaning</p></th>
  566. </tr>
  567. </thead>
  568. <tbody>
  569. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLIN</span></code></p></td>
  570. <td><p>There is data to read</p></td>
  571. </tr>
  572. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLPRI</span></code></p></td>
  573. <td><p>There is urgent data to read</p></td>
  574. </tr>
  575. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLOUT</span></code></p></td>
  576. <td><p>Ready for output: writing will not block</p></td>
  577. </tr>
  578. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLERR</span></code></p></td>
  579. <td><p>Error condition of some sort</p></td>
  580. </tr>
  581. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLHUP</span></code></p></td>
  582. <td><p>Hung up</p></td>
  583. </tr>
  584. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLRDHUP</span></code></p></td>
  585. <td><p>Stream socket peer closed connection, or
  586. shut down writing half of connection</p></td>
  587. </tr>
  588. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">POLLNVAL</span></code></p></td>
  589. <td><p>Invalid request: descriptor not open</p></td>
  590. </tr>
  591. </tbody>
  592. </table>
  593. <p>Registering a file descriptor that’s already registered is not an error, and has
  594. the same effect as registering the descriptor exactly once.</p>
  595. </dd></dl>
  596. <dl class="py method">
  597. <dt class="sig sig-object py" id="select.poll.modify">
  598. <span class="sig-prename descclassname"><span class="pre">poll.</span></span><span class="sig-name descname"><span class="pre">modify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eventmask</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.poll.modify" title="Link to this definition">¶</a></dt>
  599. <dd><p>Modifies an already registered fd. This has the same effect as
  600. <code class="docutils literal notranslate"><span class="pre">register(fd,</span> <span class="pre">eventmask)</span></code>. Attempting to modify a file descriptor
  601. that was never registered causes an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception with errno
  602. <code class="xref py py-const docutils literal notranslate"><span class="pre">ENOENT</span></code> to be raised.</p>
  603. </dd></dl>
  604. <dl class="py method">
  605. <dt class="sig sig-object py" id="select.poll.unregister">
  606. <span class="sig-prename descclassname"><span class="pre">poll.</span></span><span class="sig-name descname"><span class="pre">unregister</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.poll.unregister" title="Link to this definition">¶</a></dt>
  607. <dd><p>Remove a file descriptor being tracked by a polling object. Just like the
  608. <a class="reference internal" href="#select.poll.register" title="select.poll.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register()</span></code></a> method, <em>fd</em> can be an integer or an object with a
  609. <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method that returns an integer.</p>
  610. <p>Attempting to remove a file descriptor that was never registered causes a
  611. <a class="reference internal" href="exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception to be raised.</p>
  612. </dd></dl>
  613. <dl class="py method">
  614. <dt class="sig sig-object py" id="select.poll.poll">
  615. <span class="sig-prename descclassname"><span class="pre">poll.</span></span><span class="sig-name descname"><span class="pre">poll</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#select.poll.poll" title="Link to this definition">¶</a></dt>
  616. <dd><p>Polls the set of registered file descriptors, and returns a possibly empty list
  617. containing <code class="docutils literal notranslate"><span class="pre">(fd,</span> <span class="pre">event)</span></code> 2-tuples for the descriptors that have events or
  618. errors to report. <em>fd</em> is the file descriptor, and <em>event</em> is a bitmask with
  619. bits set for the reported events for that descriptor — <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLIN</span></code> for
  620. waiting input, <code class="xref py py-const docutils literal notranslate"><span class="pre">POLLOUT</span></code> to indicate that the descriptor can be written
  621. to, and so forth. An empty list indicates that the call timed out and no file
  622. descriptors had any events to report. If <em>timeout</em> is given, it specifies the
  623. length of time in milliseconds which the system will wait for events before
  624. returning. If <em>timeout</em> is omitted, negative, or <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, the call will
  625. block until there is an event for this poll object.</p>
  626. <div class="versionchanged">
  627. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now retried with a recomputed timeout when interrupted by
  628. a signal, except if the signal handler raises an exception (see
  629. <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising
  630. <a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p>
  631. </div>
  632. </dd></dl>
  633. </section>
  634. <section id="kqueue-objects">
  635. <span id="id1"></span><h2>Kqueue Objects<a class="headerlink" href="#kqueue-objects" title="Link to this heading">¶</a></h2>
  636. <dl class="py method">
  637. <dt class="sig sig-object py" id="select.kqueue.close">
  638. <span class="sig-prename descclassname"><span class="pre">kqueue.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.kqueue.close" title="Link to this definition">¶</a></dt>
  639. <dd><p>Close the control file descriptor of the kqueue object.</p>
  640. </dd></dl>
  641. <dl class="py attribute">
  642. <dt class="sig sig-object py" id="select.kqueue.closed">
  643. <span class="sig-prename descclassname"><span class="pre">kqueue.</span></span><span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#select.kqueue.closed" title="Link to this definition">¶</a></dt>
  644. <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the kqueue object is closed.</p>
  645. </dd></dl>
  646. <dl class="py method">
  647. <dt class="sig sig-object py" id="select.kqueue.fileno">
  648. <span class="sig-prename descclassname"><span class="pre">kqueue.</span></span><span class="sig-name descname"><span class="pre">fileno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#select.kqueue.fileno" title="Link to this definition">¶</a></dt>
  649. <dd><p>Return the file descriptor number of the control fd.</p>
  650. </dd></dl>
  651. <dl class="py method">
  652. <dt class="sig sig-object py" id="select.kqueue.fromfd">
  653. <span class="sig-prename descclassname"><span class="pre">kqueue.</span></span><span class="sig-name descname"><span class="pre">fromfd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#select.kqueue.fromfd" title="Link to this definition">¶</a></dt>
  654. <dd><p>Create a kqueue object from a given file descriptor.</p>
  655. </dd></dl>
  656. <dl class="py method">
  657. <dt class="sig sig-object py" id="select.kqueue.control">
  658. <span class="sig-prename descclassname"><span class="pre">kqueue.</span></span><span class="sig-name descname"><span class="pre">control</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">changelist</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_events</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">eventlist</span></span></span><a class="headerlink" href="#select.kqueue.control" title="Link to this definition">¶</a></dt>
  659. <dd><p>Low level interface to kevent</p>
  660. <ul class="simple">
  661. <li><p>changelist must be an iterable of kevent objects or <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
  662. <li><p>max_events must be 0 or a positive integer</p></li>
  663. <li><p>timeout in seconds (floats possible); the default is <code class="docutils literal notranslate"><span class="pre">None</span></code>,
  664. to wait forever</p></li>
  665. </ul>
  666. <div class="versionchanged">
  667. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now retried with a recomputed timeout when interrupted by
  668. a signal, except if the signal handler raises an exception (see
  669. <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising
  670. <a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p>
  671. </div>
  672. </dd></dl>
  673. </section>
  674. <section id="kevent-objects">
  675. <span id="id2"></span><h2>Kevent Objects<a class="headerlink" href="#kevent-objects" title="Link to this heading">¶</a></h2>
  676. <p><a class="reference external" href="https://man.freebsd.org/cgi/man.cgi?query=kqueue&amp;sektion=2">https://man.freebsd.org/cgi/man.cgi?query=kqueue&amp;sektion=2</a></p>
  677. <dl class="py attribute">
  678. <dt class="sig sig-object py" id="select.kevent.ident">
  679. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">ident</span></span><a class="headerlink" href="#select.kevent.ident" title="Link to this definition">¶</a></dt>
  680. <dd><p>Value used to identify the event. The interpretation depends on the filter
  681. but it’s usually the file descriptor. In the constructor ident can either
  682. be an int or an object with a <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method. kevent
  683. stores the integer internally.</p>
  684. </dd></dl>
  685. <dl class="py attribute">
  686. <dt class="sig sig-object py" id="select.kevent.filter">
  687. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">filter</span></span><a class="headerlink" href="#select.kevent.filter" title="Link to this definition">¶</a></dt>
  688. <dd><p>Name of the kernel filter.</p>
  689. <table class="docutils align-default">
  690. <thead>
  691. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  692. <th class="head"><p>Meaning</p></th>
  693. </tr>
  694. </thead>
  695. <tbody>
  696. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_READ</span></code></p></td>
  697. <td><p>Takes a descriptor and returns whenever
  698. there is data available to read</p></td>
  699. </tr>
  700. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_WRITE</span></code></p></td>
  701. <td><p>Takes a descriptor and returns whenever
  702. there is data available to write</p></td>
  703. </tr>
  704. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_AIO</span></code></p></td>
  705. <td><p>AIO requests</p></td>
  706. </tr>
  707. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_VNODE</span></code></p></td>
  708. <td><p>Returns when one or more of the requested
  709. events watched in <em>fflag</em> occurs</p></td>
  710. </tr>
  711. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_PROC</span></code></p></td>
  712. <td><p>Watch for events on a process id</p></td>
  713. </tr>
  714. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_NETDEV</span></code></p></td>
  715. <td><p>Watch for events on a network device
  716. [not available on macOS]</p></td>
  717. </tr>
  718. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_SIGNAL</span></code></p></td>
  719. <td><p>Returns whenever the watched signal is
  720. delivered to the process</p></td>
  721. </tr>
  722. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_TIMER</span></code></p></td>
  723. <td><p>Establishes an arbitrary timer</p></td>
  724. </tr>
  725. </tbody>
  726. </table>
  727. </dd></dl>
  728. <dl class="py attribute">
  729. <dt class="sig sig-object py" id="select.kevent.flags">
  730. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">flags</span></span><a class="headerlink" href="#select.kevent.flags" title="Link to this definition">¶</a></dt>
  731. <dd><p>Filter action.</p>
  732. <table class="docutils align-default">
  733. <thead>
  734. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  735. <th class="head"><p>Meaning</p></th>
  736. </tr>
  737. </thead>
  738. <tbody>
  739. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_ADD</span></code></p></td>
  740. <td><p>Adds or modifies an event</p></td>
  741. </tr>
  742. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_DELETE</span></code></p></td>
  743. <td><p>Removes an event from the queue</p></td>
  744. </tr>
  745. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_ENABLE</span></code></p></td>
  746. <td><p>Permitscontrol() to returns the event</p></td>
  747. </tr>
  748. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_DISABLE</span></code></p></td>
  749. <td><p>Disablesevent</p></td>
  750. </tr>
  751. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_ONESHOT</span></code></p></td>
  752. <td><p>Removes event after first occurrence</p></td>
  753. </tr>
  754. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_CLEAR</span></code></p></td>
  755. <td><p>Reset the state after an event is retrieved</p></td>
  756. </tr>
  757. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_SYSFLAGS</span></code></p></td>
  758. <td><p>internal event</p></td>
  759. </tr>
  760. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_FLAG1</span></code></p></td>
  761. <td><p>internal event</p></td>
  762. </tr>
  763. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_EOF</span></code></p></td>
  764. <td><p>Filter specific EOF condition</p></td>
  765. </tr>
  766. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_EV_ERROR</span></code></p></td>
  767. <td><p>See return values</p></td>
  768. </tr>
  769. </tbody>
  770. </table>
  771. </dd></dl>
  772. <dl class="py attribute">
  773. <dt class="sig sig-object py" id="select.kevent.fflags">
  774. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">fflags</span></span><a class="headerlink" href="#select.kevent.fflags" title="Link to this definition">¶</a></dt>
  775. <dd><p>Filter specific flags.</p>
  776. <p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_READ</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_WRITE</span></code> filter flags:</p>
  777. <table class="docutils align-default">
  778. <thead>
  779. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  780. <th class="head"><p>Meaning</p></th>
  781. </tr>
  782. </thead>
  783. <tbody>
  784. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_LOWAT</span></code></p></td>
  785. <td><p>low water mark of a socket buffer</p></td>
  786. </tr>
  787. </tbody>
  788. </table>
  789. <p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_VNODE</span></code> filter flags:</p>
  790. <table class="docutils align-default">
  791. <thead>
  792. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  793. <th class="head"><p>Meaning</p></th>
  794. </tr>
  795. </thead>
  796. <tbody>
  797. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_DELETE</span></code></p></td>
  798. <td><p><em>unlink()</em> was called</p></td>
  799. </tr>
  800. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_WRITE</span></code></p></td>
  801. <td><p>a write occurred</p></td>
  802. </tr>
  803. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_EXTEND</span></code></p></td>
  804. <td><p>the file was extended</p></td>
  805. </tr>
  806. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_ATTRIB</span></code></p></td>
  807. <td><p>an attribute was changed</p></td>
  808. </tr>
  809. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_LINK</span></code></p></td>
  810. <td><p>the link count has changed</p></td>
  811. </tr>
  812. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_RENAME</span></code></p></td>
  813. <td><p>the file was renamed</p></td>
  814. </tr>
  815. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_REVOKE</span></code></p></td>
  816. <td><p>access to the file was revoked</p></td>
  817. </tr>
  818. </tbody>
  819. </table>
  820. <p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_PROC</span></code> filter flags:</p>
  821. <table class="docutils align-default">
  822. <thead>
  823. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  824. <th class="head"><p>Meaning</p></th>
  825. </tr>
  826. </thead>
  827. <tbody>
  828. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_EXIT</span></code></p></td>
  829. <td><p>the process has exited</p></td>
  830. </tr>
  831. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_FORK</span></code></p></td>
  832. <td><p>the process has called <em>fork()</em></p></td>
  833. </tr>
  834. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_EXEC</span></code></p></td>
  835. <td><p>the process has executed a new process</p></td>
  836. </tr>
  837. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_PCTRLMASK</span></code></p></td>
  838. <td><p>internal filter flag</p></td>
  839. </tr>
  840. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_PDATAMASK</span></code></p></td>
  841. <td><p>internal filter flag</p></td>
  842. </tr>
  843. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_TRACK</span></code></p></td>
  844. <td><p>follow a process across <em>fork()</em></p></td>
  845. </tr>
  846. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_CHILD</span></code></p></td>
  847. <td><p>returned on the child process for
  848. <em>NOTE_TRACK</em></p></td>
  849. </tr>
  850. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_TRACKERR</span></code></p></td>
  851. <td><p>unable to attach to a child</p></td>
  852. </tr>
  853. </tbody>
  854. </table>
  855. <p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_FILTER_NETDEV</span></code> filter flags (not available on macOS):</p>
  856. <table class="docutils align-default">
  857. <thead>
  858. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  859. <th class="head"><p>Meaning</p></th>
  860. </tr>
  861. </thead>
  862. <tbody>
  863. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_LINKUP</span></code></p></td>
  864. <td><p>link is up</p></td>
  865. </tr>
  866. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_LINKDOWN</span></code></p></td>
  867. <td><p>link is down</p></td>
  868. </tr>
  869. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">KQ_NOTE_LINKINV</span></code></p></td>
  870. <td><p>link state is invalid</p></td>
  871. </tr>
  872. </tbody>
  873. </table>
  874. </dd></dl>
  875. <dl class="py attribute">
  876. <dt class="sig sig-object py" id="select.kevent.data">
  877. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">data</span></span><a class="headerlink" href="#select.kevent.data" title="Link to this definition">¶</a></dt>
  878. <dd><p>Filter specific data.</p>
  879. </dd></dl>
  880. <dl class="py attribute">
  881. <dt class="sig sig-object py" id="select.kevent.udata">
  882. <span class="sig-prename descclassname"><span class="pre">kevent.</span></span><span class="sig-name descname"><span class="pre">udata</span></span><a class="headerlink" href="#select.kevent.udata" title="Link to this definition">¶</a></dt>
  883. <dd><p>User defined value.</p>
  884. </dd></dl>
  885. </section>
  886. </section>
  887. <div class="clearer"></div>
  888. </div>
  889. </div>
  890. </div>
  891. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  892. <div class="sphinxsidebarwrapper">
  893. <div>
  894. <h3><a href="../contents.html">Table of Contents</a></h3>
  895. <ul>
  896. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code> — Waiting for I/O completion</a><ul>
  897. <li><a class="reference internal" href="#dev-poll-polling-objects"><code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> Polling Objects</a></li>
  898. <li><a class="reference internal" href="#edge-and-level-trigger-polling-epoll-objects">Edge and Level Trigger Polling (epoll) Objects</a></li>
  899. <li><a class="reference internal" href="#polling-objects">Polling Objects</a></li>
  900. <li><a class="reference internal" href="#kqueue-objects">Kqueue Objects</a></li>
  901. <li><a class="reference internal" href="#kevent-objects">Kevent Objects</a></li>
  902. </ul>
  903. </li>
  904. </ul>
  905. </div>
  906. <div>
  907. <h4>Previous topic</h4>
  908. <p class="topless"><a href="ssl.html"
  909. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code> — TLS/SSL wrapper for socket objects</a></p>
  910. </div>
  911. <div>
  912. <h4>Next topic</h4>
  913. <p class="topless"><a href="selectors.html"
  914. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code> — High-level I/O multiplexing</a></p>
  915. </div>
  916. <div role="note" aria-label="source link">
  917. <h3>This Page</h3>
  918. <ul class="this-page-menu">
  919. <li><a href="../bugs.html">Report a Bug</a></li>
  920. <li>
  921. <a href="https://github.com/python/cpython/blob/main/Doc/library/select.rst"
  922. rel="nofollow">Show Source
  923. </a>
  924. </li>
  925. </ul>
  926. </div>
  927. </div>
  928. <div id="sidebarbutton" title="Collapse sidebar">
  929. <span>«</span>
  930. </div>
  931. </div>
  932. <div class="clearer"></div>
  933. </div>
  934. <div class="related" role="navigation" aria-label="related navigation">
  935. <h3>Navigation</h3>
  936. <ul>
  937. <li class="right" style="margin-right: 10px">
  938. <a href="../genindex.html" title="General Index"
  939. >index</a></li>
  940. <li class="right" >
  941. <a href="../py-modindex.html" title="Python Module Index"
  942. >modules</a> |</li>
  943. <li class="right" >
  944. <a href="selectors.html" title="selectors — High-level I/O multiplexing"
  945. >next</a> |</li>
  946. <li class="right" >
  947. <a href="ssl.html" title="ssl — TLS/SSL wrapper for socket objects"
  948. >previous</a> |</li>
  949. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  950. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  951. <li class="switchers">
  952. <div class="language_switcher_placeholder"></div>
  953. <div class="version_switcher_placeholder"></div>
  954. </li>
  955. <li>
  956. </li>
  957. <li id="cpython-language-and-version">
  958. <a href="../index.html">3.12.3 Documentation</a> &#187;
  959. </li>
  960. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  961. <li class="nav-item nav-item-2"><a href="ipc.html" >Networking and Interprocess Communication</a> &#187;</li>
  962. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code> — Waiting for I/O completion</a></li>
  963. <li class="right">
  964. <div class="inline-search" role="search">
  965. <form class="inline-search" action="../search.html" method="get">
  966. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  967. <input type="submit" value="Go" />
  968. </form>
  969. </div>
  970. |
  971. </li>
  972. <li class="right">
  973. <label class="theme-selector-label">
  974. Theme
  975. <select class="theme-selector" oninput="activateTheme(this.value)">
  976. <option value="auto" selected>Auto</option>
  977. <option value="light">Light</option>
  978. <option value="dark">Dark</option>
  979. </select>
  980. </label> |</li>
  981. </ul>
  982. </div>
  983. <div class="footer">
  984. &copy;
  985. <a href="../copyright.html">
  986. Copyright
  987. </a>
  988. 2001-2024, Python Software Foundation.
  989. <br />
  990. This page is licensed under the Python Software Foundation License Version 2.
  991. <br />
  992. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  993. <br />
  994. See <a href="/license.html">History and License</a> for more information.<br />
  995. <br />
  996. The Python Software Foundation is a non-profit corporation.
  997. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  998. <br />
  999. <br />
  1000. Last updated on Apr 09, 2024 (13:47 UTC).
  1001. <a href="/bugs.html">Found a bug</a>?
  1002. <br />
  1003. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1004. </div>
  1005. </body>
  1006. </html>
上海开阖软件有限公司 沪ICP备12045867号-1