diff --git a/mitogen/parent.py b/mitogen/parent.py index fa3092c19..f301a42c5 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1429,7 +1429,9 @@ def _first_stage(): os.environ['ARGV0']=sys.executable os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)') os.write(1,'MITO000\n'.encode()) - C=zlib.decompress(os.fdopen(0,'rb').read(PREAMBLE_COMPRESSED_LEN)) + fp=os.fdopen(0,'rb') + C=zlib.decompress(fp.read(PREAMBLE_COMPRESSED_LEN)) + fp.close() fp=os.fdopen(W,'wb',0) fp.write(C) fp.close() diff --git a/tests/data/fd_check.py b/tests/data/fd_check.py index 0a87a95e9..f3684443a 100755 --- a/tests/data/fd_check.py +++ b/tests/data/fd_check.py @@ -26,6 +26,7 @@ def controlling_tty(): return None +out_path = sys.argv[1] fd = int(sys.argv[2]) st = os.fstat(fd) @@ -35,7 +36,7 @@ def controlling_tty(): else: buf = os.read(fd, 4).decode() -open(sys.argv[1], 'w').write(repr({ +output = repr({ 'buf': buf, 'flags': fcntl.fcntl(fd, fcntl.F_GETFL), 'st_mode': st.st_mode, @@ -43,4 +44,21 @@ def controlling_tty(): 'st_ino': st.st_ino, 'ttyname': ttyname(fd), 'controlling_tty': controlling_tty(), -})) +}) + +try: + out_f = open(out_path, 'w') +except Exception: + exc = sys.exc_info()[1] + sys.stderr.write("Failed to open %r: %r" % (out_path, exc)) + sys.exit(1) + +try: + out_f.write(output) +except Exception: + out_f.close() + exc = sys.exc_info()[1] + sys.stderr.write("Failed to write to %r: %r" % (out_path, exc)) + sys.exit(2) + +out_f.close() diff --git a/tox.ini b/tox.ini index 7f0123745..0446a1810 100644 --- a/tox.ini +++ b/tox.ini @@ -105,8 +105,6 @@ setenv = NOCOVERAGE_ERASE = 1 NOCOVERAGE_REPORT = 1 PIP_CONSTRAINT={toxinidir}/tests/constraints.txt - # Print a warning on the first occurence at each module:linenno. Available Python 2.7, 3.2+. - PYTHONWARNINGS=default # Ansible 6 - 8 (ansible-core 2.13 - 2.15) require Python 2.7 or >= 3.5 on targets ansible6: MITOGEN_TEST_DISTRO_SPECS=centos7 centos8 debian9 debian10 debian11 ubuntu1604 ubuntu1804 ubuntu2004 ansible7: MITOGEN_TEST_DISTRO_SPECS=centos7 centos8 debian9 debian10 debian11 ubuntu1604 ubuntu1804 ubuntu2004 @@ -137,6 +135,9 @@ setenv = mode_debops_common: MODE=debops_common mode_localhost: ANSIBLE_SKIP_TAGS=issue_776,resource_intensive mode_mitogen: MODE=mitogen + # Print a warning on the first occurence at each module:linenno. + # Availability: Python 2.7, 3.2+. + py313: PYTHONWARNINGS=default strategy_linear: ANSIBLE_STRATEGY=linear allowlist_externals = # Added: Tox 3.18: Tox 4.0+