Distributed self-replicating programs in Python
Go to file
Alex Willmer 3a31a7d886 mitogen: Workaround CPython importlib PermissionError when cwd is unreadable
On macOS when using a become plugin as an unprivileged user, to another
unprivileged user it is likely that the current working directory can't be
read. In this case os.cwd() raises PermissionError.

On versions of Python currently in the wild (March 2024, CPython <= 3.13) if
any non-builtin or non-frozen module (e.g. zlib, base64) is imported then
`importlib._bootstrap_external.PathFinder._path_importer_cache()` attempts to
call os.cwd() without catching PermissionError.

The previous comment about needing an extra .encode() appears to be wrong,
atleast for Python 3.x >= 3.6.

Command size increased by 54 bytes, bootstrap by 804 bytes. Changed from
codecs module to binascii & zlib because they're extensions, and importing
them triggers fewer supporting imports (e.g. encodings module).

Before

```
✗ ./preamble_size.py
SSH command size: 705
Bootstrap (mitogen.core) size: 17078 (16.68KiB)

                              Original          Minimized           Compressed
mitogen.parent            97884 95.6KiB  50515 49.3KiB 51.6%  12727 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           41699 40.7KiB  22477 22.0KiB 53.9%   5885  5.7KiB
14.1%
mitogen.fakessh           15577 15.2KiB   7989  7.8KiB 51.3%   2623  2.6KiB
16.8%
mitogen.master            51398 50.2KiB  25715 25.1KiB 50.0%   6886  6.7KiB
13.4%
```

After

```
✗ ./preamble_size.py
SSH command size: 759
Bootstrap (mitogen.core) size: 17882 (17.46KiB)

                              Original          Minimized           Compressed
mitogen.parent            98173 95.9KiB  50571 49.4KiB 51.5%  12747 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           41699 40.7KiB  22477 22.0KiB 53.9%   5885  5.7KiB
14.1%
mitogen.fakessh           15577 15.2KiB   7989  7.8KiB 51.3%   2623  2.6KiB
16.8%
mitogen.master            56116 54.8KiB  29427 28.7KiB 52.4%   7627  7.4KiB
13.6%
```

Fixes #885
Refs https://github.com/python/cpython/issues/115911
2024-03-17 14:54:46 +00:00
.ci ci: Fix Python 2.7 builds on macOS 11 2024-01-10 10:04:10 +00:00
.github chore: Add issue templates for 0.2 vs 0.3 releases 2021-02-09 21:35:14 +00:00
ansible_mitogen non functional: Add comments about imp module removal in Python 3.12 2024-01-31 09:50:29 +00:00
docs mitogen: Workaround CPython importlib PermissionError when cwd is unreadable 2024-03-17 14:54:46 +00:00
examples Replace os.system() with subprocess.check_call() 2022-04-21 20:19:51 +01:00
mitogen mitogen: Workaround CPython importlib PermissionError when cwd is unreadable 2024-03-17 14:54:46 +00:00
scripts remove unused imports flagged by lgtm 2019-07-31 11:46:23 +01:00
tests tests: Clarify transport config tests optimisation & correct value 2024-03-04 16:09:48 +00:00
.gitignore Ignore Ansible retry files 2024-03-04 13:38:09 +00:00
.lgtm.yml Whoops, merge together lgtm.yml and .lgtm.yml 2019-08-13 10:16:41 +01:00
LICENSE Bump copyright year and use generic author name (testing Travis) 2021-01-14 20:07:47 +00:00
MANIFEST.in setup.py: include LICENSE; closes #538. 2019-02-12 16:15:52 +00:00
README.md Abandon Travis CI We have no credits, and its a PITA to maintain two CI platforms. The tests running on Travis provide very little extra coverage vs Azure Pipelines alone 2021-10-20 02:03:12 +01:00
dev_requirements.txt Split dev_requirements.txt up according to test mode. 2018-11-06 17:00:17 +00:00
preamble_size.py mitogen.parent: Remove tabs from minimized first stage 2021-11-18 18:40:19 +00:00
run_tests tests: Remove unittest2, use stdlib unittest 2022-04-20 17:54:12 +01:00
setup.cfg Declare universal wheel support 2021-01-27 20:19:56 +00:00
setup.py Add Python 3.11 support 2023-08-11 09:35:54 +01:00
tox.ini docs: Fix generation of static website 2023-08-15 14:16:11 +01:00

README.md