Broken network handling in python application

Hello,

I am trying to create a proper AppImage package for the app activitywatch.

The package seems to be fine, but when I try to open .AppImage file I got I get errors:

ConnectionAbortedError: [Errno 103] Software caused connection abort: '/tmp/.mount_ActiviFn6gM2/aw-watcher-window/aw-watcher-window'
...
OSError: [Errno 107] Transport endpoint is not connected: '/tmp/.mount_ActiviFn6gM2/aw-watcher-afk/aw-watcher-afk'
...
ImportError: Loader FrozenImporter cannot handle module http.client
Full error
Traceback (most recent call last):
  File "PyInstaller/loader/pyimod02_importers.py", line 298, in get_code
  File "PyInstaller/loader/pyimod01_archive.py", line 291, in extract
  File "PyInstaller/loader/pyimod01_archive.py", line 87, in __enter__
ConnectionAbortedError: [Errno 103] Software caused connection abort: '/tmp/.mount_ActiviFn6gM2/aw-watcher-window/aw-watcher-window'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "aw_watcher_window/__main__.py", line 1, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_watcher_window/__init__.py", line 3, in <module>
Traceback (most recent call last):
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "PyInstaller/loader/pyimod02_importers.py", line 298, in get_code
  File "aw_watcher_window/main.py", line 8, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "PyInstaller/loader/pyimod01_archive.py", line 291, in extract
  File "aw_core/__init__.py", line 12, in <module>
  File "PyInstaller/loader/pyimod01_archive.py", line 87, in __enter__
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_core/models.py", line 1, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 482, in exec_module
  File "PyInstaller/loader/pyimod02_importers.py", line 300, in get_code
ImportError: Loader FrozenImporter cannot handle module json
[26439] Failed to execute script '__main__' due to unhandled exception!
OSError: [Errno 107] Transport endpoint is not connected: '/tmp/.mount_ActiviFn6gM2/aw-watcher-afk/aw-watcher-afk'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "aw_watcher_afk/__main__.py", line 3, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_watcher_afk/__init__.py", line 1, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_watcher_afk/__main__.py", line 3, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_watcher_afk/afk.py", line 9, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_client/__init__.py", line 1, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "aw_client/client.py", line 11, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "requests/__init__.py", line 43, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "urllib3/__init__.py", line 11, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "urllib3/exceptions.py", line 3, in <module>
  File "urllib3/packages/six.py", line 234, in create_module
  File "urllib3/packages/six.py", line 209, in load_module
  File "urllib3/packages/six.py", line 118, in _resolve
  File "urllib3/packages/six.py", line 87, in _import_module
  File "PyInstaller/loader/pyimod02_importers.py", line 482, in exec_module
  File "PyInstaller/loader/pyimod02_importers.py", line 300, in get_code
ImportError: Loader FrozenImporter cannot handle module http.client
[26438] Failed to execute script '__main__' due to unhandled exception!

It seems to be a network-related error.
The same app launched without AppImage works properly.

What can I do to fix it?

Example for quick reproduction:

wget https://github.com/ActivityWatch/activitywatch/releases/download/v0.12.0/activitywatch-v0.12.0-linux-x86_64.zip
ZIP_FILE=`ls ./ -1 |grep zip`
unzip ./$ZIP_FILE
#Launching ./activitywatch/aw-qt # Now would be successful
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x appimagetool-x86_64.AppImage
echo '#!/bin/sh
DIR="$(dirname "$(readlink -f "${0}")")"
"${DIR}"/aw-qt'>activitywatch/AppRun
chmod a+x ./activitywatch/AppRun
./linuxdeploy-x86_64.AppImage --appdir activitywatch --executable ./activitywatch/aw-qt --output appimage --desktop-file ./activitywatch/aw-qt.desktop --icon-file ./activitywatch/aw-server-rust/static/static/logo.png --icon-filename activitywatch
1 Like

Can it be caused by usage of multiple executables?

Application aw-qt calls apps aw-server, aw-watcher-window and aw-watcher-afk.

Hello, I don’t know how that application works.
Please ask the team over at GitHub - ActivityWatch/activitywatch: The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused. to release an officially supported AppImage. Thanks!

I am the one, who prepares the release of that officially supported AppImage :slight_smile:

Could you tell me what is the difference between ragular way of launching appimage

./ActivityWatch-x86_64.AppImage --appimage-mount

and mounting it and launching AppRun file?

./ActivityWatch-x86_64.AppImage --appimage-mount

cd /tmp/.mount_Activi72i8d6
./AppRun

Because doing it in the second way launches app properly.

Can it be that your application exits a process (and then possibly starts another process)? As soon as the AppRun process exits, the AppImage gets unmounted.