Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Jan 20, 2025
1 parent dba22f5 commit 177d1dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ansible_mitogen/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,12 @@ def _run_cmd():
continue

stdout_text = to_text(stdout, errors=encoding_errors)
stderr_text = to_text(stderr, errors=encoding_errors)

return {
'rc': rc,
'stdout': stdout_text,
'stdout_lines': stdout_text.splitlines(),
'stderr': stderr,
'stderr': stderr_text,
'stderr_lines': stderr_text.splitlines(),
}
18 changes: 10 additions & 8 deletions mitogen/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,18 +1424,20 @@ def _first_stage():
os.close(r)
os.close(W)
os.close(w)
if os.uname()[0]=='Darwin'and os.uname()[2][:2]<'19'and sys.executable=='/usr/bin/python':sys.executable='/usr/bin/python2.7'
if os.uname()[0]=='Darwin'and os.uname()[2][:2]<'19'and sys.executable=='/usr/bin/python':sys.executable+='2.7'
if os.uname()[0]=='Darwin'and os.uname()[2][:2]in'2021'and sys.version[:3]=='2.7':os.environ['PYTHON_LAUNCHED_FROM_WRAPPER']='1'
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(W,'wb',0)
fp.write(C)
fp.close()
fp=os.fdopen(w,'wb',0)
fp.write(C)
fp.close()
f=os.fdopen(0,'rb')
C=zlib.decompress(f.read(PREAMBLE_COMPRESSED_LEN))
f.close()
f=os.fdopen(W,'wb',0)
f.write(C)
f.close()
f=os.fdopen(w,'wb',0)
f.write(C)
f.close()
os.write(1,'MITO001\n'.encode())
os.close(2)

Expand Down
22 changes: 20 additions & 2 deletions tests/data/fd_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def controlling_tty():
return None


out_path = sys.argv[1]
fd = int(sys.argv[2])
st = os.fstat(fd)

Expand All @@ -35,12 +36,29 @@ 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,
'st_dev': st.st_dev,
'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()
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ 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
PYTHONWARNINGS=default:::ansible_mitogen,default:::mitogen
# 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
Expand Down

0 comments on commit 177d1dd

Please sign in to comment.