Skip to content

Commit fa9f65e

Browse files
bpo-46364: Use sockets for stdin of asyncio only on AIX (GH-30596)
Signed-off-by: Christoph Hamsen <hamsen.christoph@posteo.de> Co-authored-by: July Tikhonov <july.tikh@gmail.com> (cherry picked from commit c9ed032) Co-authored-by: Christoph Hamsen <37963496+xopham@users.noreply.github.com>
1 parent c766242 commit fa9f65e

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Lib/asyncio/unix_events.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,11 @@ class _UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport):
789789

790790
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
791791
stdin_w = None
792-
if stdin == subprocess.PIPE:
793-
# Use a socket pair for stdin, since not all platforms
792+
if stdin == subprocess.PIPE and sys.platform.startswith('aix'):
793+
# Use a socket pair for stdin on AIX, since it does not
794794
# support selecting read events on the write end of a
795795
# socket (which we use in order to detect closing of the
796-
# other end). Notably this is needed on AIX, and works
797-
# just fine on other platforms.
796+
# other end).
798797
stdin, stdin_w = socket.socketpair()
799798
try:
800799
self._proc = subprocess.Popen(

Lib/test/test_asyncio/test_subprocess.py

+20
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,26 @@ async def empty_error():
401401
self.assertEqual(output, None)
402402
self.assertEqual(exitcode, 0)
403403

404+
@unittest.skipIf(sys.platform != 'linux', "Don't have /dev/stdin")
405+
def test_devstdin_input(self):
406+
407+
async def devstdin_input(message):
408+
code = 'file = open("/dev/stdin"); data = file.read(); print(len(data))'
409+
proc = await asyncio.create_subprocess_exec(
410+
sys.executable, '-c', code,
411+
stdin=asyncio.subprocess.PIPE,
412+
stdout=asyncio.subprocess.PIPE,
413+
stderr=asyncio.subprocess.PIPE,
414+
close_fds=False,
415+
)
416+
stdout, stderr = await proc.communicate(message)
417+
exitcode = await proc.wait()
418+
return (stdout, exitcode)
419+
420+
output, exitcode = self.loop.run_until_complete(devstdin_input(b'abc'))
421+
self.assertEqual(output.rstrip(), b'3')
422+
self.assertEqual(exitcode, 0)
423+
404424
def test_cancel_process_wait(self):
405425
# Issue #23140: cancel Process.wait()
406426

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restrict use of sockets instead of pipes for stdin of subprocesses created by :mod:`asyncio` to AIX platform only.

0 commit comments

Comments
 (0)