@@ -1263,7 +1263,9 @@ Working with pipes
12631263 *protocol_factory * must be a callable returning an
12641264 :ref: `asyncio protocol <asyncio-protocol >` implementation.
12651265
1266- *pipe * is a :term: `file-like object <file object> `.
1266+ *pipe * is a :term: `file-like object <file object> `. Not every file-like
1267+ object is accepted; see :ref: `Supported pipe objects
1268+ <asyncio-pipe-objects>` below.
12671269
12681270 Return pair ``(transport, protocol) ``, where *transport * supports
12691271 the :class: `ReadTransport ` interface and *protocol * is an object
@@ -1280,7 +1282,9 @@ Working with pipes
12801282 *protocol_factory * must be a callable returning an
12811283 :ref: `asyncio protocol <asyncio-protocol >` implementation.
12821284
1283- *pipe * is :term: `file-like object <file object> `.
1285+ *pipe * is a :term: `file-like object <file object> `. Not every file-like
1286+ object is accepted; see :ref: `Supported pipe objects
1287+ <asyncio-pipe-objects>` below.
12841288
12851289 Return pair ``(transport, protocol) ``, where *transport * supports
12861290 :class: `WriteTransport ` interface and *protocol * is an object
@@ -1289,6 +1293,44 @@ Working with pipes
12891293 With :class: `SelectorEventLoop ` event loop, the *pipe * is set to
12901294 non-blocking mode.
12911295
1296+ .. _asyncio-pipe-objects :
1297+
1298+ .. rubric :: Supported pipe objects
1299+
1300+ Even though the *pipe * argument is a :term: `file-like object <file object> `,
1301+ these methods only work with objects the operating system can poll for
1302+ readiness or perform overlapped I/O on. Regular files on disk are **not **
1303+ supported on any platform, and neither are :data: `sys.stdin `,
1304+ :data: `sys.stdout ` and :data: `sys.stderr ` when they have been redirected to
1305+ or from a regular file. There is no asynchronous file I/O in asyncio; use
1306+ :meth: `loop.run_in_executor ` to read and write regular files without
1307+ blocking the event loop.
1308+
1309+ On Unix, with :class: `SelectorEventLoop `, *pipe * must wrap one of the
1310+ following:
1311+
1312+ * a pipe, such as an end of an :func: `os.pipe ` pair or a FIFO created with
1313+ :func: `os.mkfifo `;
1314+ * a socket;
1315+ * a character device, such as a terminal. This is why :data: `sys.stdin `
1316+ works when the program is run interactively but fails when its input is
1317+ redirected from a file.
1318+
1319+ Anything else, a regular file in particular, raises :exc: `ValueError `.
1320+
1321+ On Windows, where only :class: `ProactorEventLoop ` implements these methods,
1322+ *pipe * must wrap a handle opened for overlapped I/O, since the handle has to
1323+ be associated with an I/O completion port. In practice this means a named
1324+ pipe, such as the ones created by :func: `!asyncio.windows_utils.pipe ` and
1325+ used for the standard streams of a subprocess started by
1326+ :meth: `loop.subprocess_exec `. Console handles and regular file handles
1327+ cannot be associated with a completion port, so :data: `sys.stdin ` and files
1328+ opened with :func: `open ` do not work. Unlike on Unix, this is not reported
1329+ by the method itself: it returns successfully and the resulting
1330+ :exc: `OSError ` is later passed to the
1331+ :meth: `event loop exception handler <loop.call_exception_handler> ` when the
1332+ transport first reads or writes.
1333+
12921334.. note ::
12931335
12941336 :class: `SelectorEventLoop ` does not support the above methods on
0 commit comments