Require blocking IO for ansible CLI. (#77639)

pull/77663/head
Matt Clay 4 years ago committed by GitHub
parent 62d03c8e75
commit e2d54d3594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
minor_changes:
- ansible - At startup the stdin/stdout/stderr file handles are checked to verify they are using blocking IO.
If not, the process exits with an error reporting which file handle(s) are using non-blocking IO.

@ -7,6 +7,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import os
import sys import sys
# Used for determining if the system is running a new enough python version # Used for determining if the system is running a new enough python version
@ -17,6 +18,28 @@ if sys.version_info < (3, 8):
'Current version: %s' % ''.join(sys.version.splitlines()) 'Current version: %s' % ''.join(sys.version.splitlines())
) )
def check_blocking_io():
"""Check stdin/stdout/stderr to make sure they are using blocking IO."""
handles = []
for handle in (sys.stdin, sys.stdout, sys.stderr):
# noinspection PyBroadException
try:
fd = handle.fileno()
except Exception:
continue # not a real file handle, such as during the import sanity test
if not os.get_blocking(fd):
handles.append(getattr(handle, 'name', None) or '#%s' % fd)
if handles:
raise SystemExit('ERROR: Ansible requires blocking IO on stdin/stdout/stderr. '
'Non-blocking file handles detected: %s' % ', '.join(_io for _io in handles))
check_blocking_io()
from importlib.metadata import version from importlib.metadata import version
from ansible.module_utils.compat.version import LooseVersion from ansible.module_utils.compat.version import LooseVersion
@ -31,7 +54,6 @@ if jinja2_version < LooseVersion('3.0'):
import errno import errno
import getpass import getpass
import os
import subprocess import subprocess
import traceback import traceback
from abc import ABC, abstractmethod from abc import ABC, abstractmethod

Loading…
Cancel
Save