Skip to content

Commit 552819e

Browse files
committed
mitogen.parent: Detect and avoid Python2.7 wrapper on macOS 11 & 12
Without this errors such as the following occur ``` ✗ MITOGEN_LOG_LEVEL=DEBUG python3 foo.py Python: execv: (null): No such file or directory Traceback (most recent call last): File "foo.py", line 16, in <module> target = router.local(python_path='/usr/bin/python2.7', debug=True) File "/Users/alex/src/mitogen2/mitogen/parent.py", line 2486, in local return self.connect(u'local', **kwargs) File "/Users/alex/src/mitogen2/mitogen/parent.py", line 2446, in connect return self._connect(klass, **mitogen.core.Kwargs(kwargs)) File "/Users/alex/src/mitogen2/mitogen/parent.py", line 2426, in _connect conn.connect(context=context) File "/Users/alex/src/mitogen2/mitogen/parent.py", line 1708, in connect raise self.exception mitogen.parent.EofError: EOF on stream; last 100 lines received: MITO000 MITO001 ``` Before ``` $ ./preamble_size.py SSH command size: 625 Bootstrap (mitogen.core) size: 17007 (16.61KiB) Original Minimized Compressed mitogen.parent 97496 95.2KiB 50355 49.2KiB 51.6% 12663 12.4KiB 13.0% mitogen.fork 8436 8.2KiB 4130 4.0KiB 49.0% 1648 1.6KiB 19.5% mitogen.ssh 10892 10.6KiB 6952 6.8KiB 63.8% 2113 2.1KiB 19.4% mitogen.sudo 12089 11.8KiB 5924 5.8KiB 49.0% 2249 2.2KiB 18.6% mitogen.select 12325 12.0KiB 2929 2.9KiB 23.8% 964 0.9KiB 7.8% mitogen.service 41644 40.7KiB 22431 21.9KiB 53.9% 5886 5.7KiB 14.1% mitogen.fakessh 15599 15.2KiB 8011 7.8KiB 51.4% 2624 2.6KiB 16.8% mitogen.master 48732 47.6KiB 24569 24.0KiB 50.4% 6768 6.6KiB 13.9% ``` After ``` $ ./preamble_size.py SSH command size: 705 Bootstrap (mitogen.core) size: 17007 (16.61KiB) Original Minimized Compressed mitogen.parent 97885 95.6KiB 50516 49.3KiB 51.6% 12728 12.4KiB 13.0% mitogen.fork 8436 8.2KiB 4130 4.0KiB 49.0% 1648 1.6KiB 19.5% mitogen.ssh 10892 10.6KiB 6952 6.8KiB 63.8% 2113 2.1KiB 19.4% mitogen.sudo 12089 11.8KiB 5924 5.8KiB 49.0% 2249 2.2KiB 18.6% mitogen.select 12325 12.0KiB 2929 2.9KiB 23.8% 964 0.9KiB 7.8% mitogen.service 41644 40.7KiB 22431 21.9KiB 53.9% 5886 5.7KiB 14.1% mitogen.fakessh 15599 15.2KiB 8011 7.8KiB 51.4% 2624 2.6KiB 16.8% mitogen.master 48733 47.6KiB 24570 24.0KiB 50.4% 6771 6.6KiB 13.9% ```
1 parent 4c02ea6 commit 552819e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
2121
v0.3.1.dev0 (unreleased)
2222
------------------------
2323

24+
* :gh:issue:`774` Fix bootstrap failures on macOS 11.x and 12.x, involving Python 2.7 wrapper
2425
* :gh:issue:`834` Support for Ansible 3 and 4 (ansible-core 2.11)
2526
* :gh:issue:`869` Continuous Integration tests are now run with Tox
2627
* :gh:issue:`869` Continuous Integration tests now cover CentOS 6 & 8, Debian 9 & 11, Ubuntu 16.04 & 20.04

mitogen/parent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,9 +1412,12 @@ def __repr__(self):
14121412
# * macOS <= 10.14 (Darwin <= 18) install an unreliable Python version
14131413
# switcher as /usr/bin/python, which introspects argv0. To workaround
14141414
# it we redirect attempts to call /usr/bin/python with an explicit
1415-
# call to /usr/bin/python2.7. macOS 10.15+ (Darwin 19+) removed it.
1416-
# On these versions /usr/bin/python is a symlink to
1417-
# /System/Library/Frameworks/Python.framework/Versions/2.7/.../Python
1415+
# call to /usr/bin/python2.7. macOS 10.15 (Darwin 19) removed it.
1416+
# * macOS 11.x (Darwin 20, Big Sur) and macOS 12.x (Darwin 21, Montery)
1417+
# do something slightly different. The Python executable is patched to
1418+
# perform an extra execvp(). I don't fully understand the details, but
1419+
# setting PYTHON_LAUNCHED_FROM_WRAPPER=1 avoids it.
1420+
# * macOS 13.x (Darwin 22?) may remove python 2.x entirely.
14181421
#
14191422
# Locals:
14201423
# R: read side of interpreter stdin.
@@ -1437,7 +1440,8 @@ def _first_stage():
14371440
os.close(r)
14381441
os.close(W)
14391442
os.close(w)
1440-
if sys.executable+sys.platform=='/usr/bin/pythondarwin'and os.uname()[2]<'19':sys.executable+='2.7'
1443+
if os.uname()[0]=='Darwin'and os.uname()[2][:2]<'19'and sys.executable=='/usr/bin/python':sys.executable='/usr/bin/python2.7'
1444+
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'
14411445
os.environ['ARGV0']=sys.executable
14421446
os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)')
14431447
os.write(1,'MITO000\n'.encode())

0 commit comments

Comments
 (0)