AppImage / AppImage/AppImageKit

AppImage breaks nested launching from Python

Open
#1,435 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
9.4k
Forks
588
PR merge metrics
PR metrics pending

Description

The problem demonstrated on an extracted AppImage:

```python
[0] % ./AppRun
Traceback (most recent call last):
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/bin/scc", line 8, in
sys.exit(main())
~~~~^^
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/site-packages/scc/scripts.py", line 412, in main
sys.exit(command(sys.argv[0], sys.argv[2:]))
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/site-packages/scc/scripts.py", line 47, in cmd_gui
return run_binary("sc-controller", argv)
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/site-packages/scc/scripts.py", line 30, in run_binary
child = subprocess.Popen([binary] + argv)
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/subprocess.py", line 1039, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass_fds, cwd, env,
^^^^^^^^^^^^^^^^^^^
...<5 lines>...
gid, gids, uid, umask,
^^^^^^^^^^^^^^^^^^^^^^
start_new_session, process_group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/subprocess.py", line 1857, in _execute_child
self._posix_spawn(args, executable, env, restore_signals, close_fds,
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
p2cread, p2cwrite,
^^^^^^^^^^^^^^^^^^
c2pread, c2pwrite,
^^^^^^^^^^^^^^^^^^
errread, errwrite)
^^^^^^^^^^^^^^^^^^
File "/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/lib/python3.13/subprocess.py", line 1801, in _posix_spawn
self.pid = os.posix_spawn(executable, args, env, **kwargs)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/c0rn3j/Downloads/appimage-trixie-amd64/squashfs-root/usr/bin/sc-controller'
```
Now, changing the `usr/bin/env python` in `sc-controller` to `/usr/bin/env python` solves this, because it no longer tries to load the AppImage-castrated `env` binary that relies on `lib64/ld-linux-x86-64.so.2` to exist, but we're not in `runtime/compat` where it resides.

So we get this wonderful error when launching directly, and the same issue will break the binary when launched through Python:

```bash
./env
zsh: no such file or directory: ./env
```

Now, the `scripts.py` is launching it this way: https://github.com/C0rn3j/sc-controller/blob/5a8e3025f75c214a54db05d438e2bbab015cf057/scc/scripts.py#L28

This works on Python 3.12 and earlier, but not Python 3.13, since that now uses `posix_spawn()` by default in this situation - https://docs.python.org/3/whatsnew/3.13.html#subprocess

A workaround is to preface `subprocess.Popen` calls with:

```python
subprocess._USE_POSIX_SPAWN = False
```

Or replacing the shebang with the host's `/usr/bin/env`, if `env` is all you use in your shebangs.

What am I supposed to do here?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.