# Broken network handling in python application

**URL:** <https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833>\
**Category:** Creating AppImages\
**Created:** [September 26, 2022, 4:36pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833 "2022-09-26T16:36:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pktiuk](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/pktiuk/32/430_2.png) [@pktiuk](https://discourse.appimage.org/u/pktiuk)\
**Post date:** [September 26, 2022, 4:36pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833/1 "2022-09-26T16:36:59Z")

</div>

Hello,

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

> <https://github.com/ActivityWatch/activitywatch/pull/772>
>
> Closes: https://github.com/ActivityWatch/activitywatch/issues/725

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

```auto
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**
>
> ```auto
> 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:

```bash
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

```

---

<div class="post-metadata">

**Author:** ![pktiuk](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/pktiuk/32/430_2.png) [@pktiuk](https://discourse.appimage.org/u/pktiuk)\
**Post date:** [September 29, 2022, 2:20pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833/2 "2022-09-29T14:20:02Z")

</div>

Can it be caused by usage of multiple executables?

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

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [October 1, 2022, 3:46pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833/3 "2022-10-01T15:46:35Z")

</div>

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.](https://github.com/ActivityWatch/activitywatch) to release an officially supported AppImage. Thanks!

---

<div class="post-metadata">

**Author:** ![pktiuk](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/pktiuk/32/430_2.png) [@pktiuk](https://discourse.appimage.org/u/pktiuk)\
**Post date:** [October 1, 2022, 4:59pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833/4 "2022-10-01T16:59:02Z")

</div>

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

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`

```auto
cd /tmp/.mount_Activi72i8d6
./AppRun

```

Because doing it in the second way launches app properly.

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 27, 2023, 4:52pm UTC](https://discourse.appimage.org/t/broken-network-handling-in-python-application/2833/5 "2023-03-27T16:52:30Z")

</div>

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.
