aTrain snap building - problems (mainly multiprocessing)

Hi everyone,

I am trying to package our python app aTrain, a local audio transcription GUI app based on whisper, as a snap.

I actually got quite far, getting it to mostly run in devmode confinement. However, when I switched to strict confinement I got a problem with permissions for multiprocessing:

  File "/usr/lib/python3.12/multiprocessing/synchronize.py", line 57, in __init__
    sl = self._semlock = _multiprocessing.SemLock(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied

Here are the two corresponding branches for the app and the backend.

To reproduce, clone the aTrain repository and switch to the feature snap branch, then run snapcraft to build (warning: takes a few GB).

Any ideas on how to fix this would be much appreciated, or alternatively the info that this is intended behavior of strict confinement and no solution is possible.

I also have number of smaller questions (like how to make created transcripts more easily accessible for users) after the big problems are fixed.

Below is also my snapcraft.yaml (also in the aTrain feature_snap branch)

Best, Jürgen

name: atrain
summary: aTrain summary
description: |
    A GUI tool for offline transcription of speech recordings, including speaker diarization, utilizing state-of-the-art machine learning models.
version: test
base: core24
confinement: strict

parts:
  atrain:
    plugin: python
    source: .
    python-packages:
      - pyqt5
      - pyqtwebengine
      - pywebview
      - pywebview[qt]
      - pycairo
      - PyGObject == 3.50.0
      - lightning-utilities
      - numpy == 1.26.4
      - packaging
    build-environment:
      - PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cu121
    build-packages:
      - git
      - build-essential
      - libgl1-mesa-dev
      - libcairo2
      - libcairo2-dev
      - libgirepository1.0-dev
      - libglu1-mesa
      - libwebkit2gtk-4.1-dev
    stage-packages:
      - libgl1
      - libglx0
      - libglvnd0
      - libxau6
      - libxdmcp6
      - libx11-6
      - libavfilter-dev
      - libxcb-randr0-dev 
      - libxcb-xtest0-dev 
      - libxcb-xinerama0-dev 
      - libxcb-shape0-dev 
      - libxcb-xkb-dev
      - libavcodec-dev
      - libavcodec-extra
      - libavutil-dev
      - libavfilter-dev
      - libavformat-dev
      - libxcb-xinput0
      - qtcreator 
      - qtbase5-dev
      - qt5-qmake 
      - cmake

apps:
  atrain:
    command: bin/aTrain start
    plugs:
      - desktop
      - desktop-legacy
      - opengl
      - x11
      - wayland
      - network
      - network-bind
      - network-status
      - browser-support
    extensions: [gnome]
    environment:
       LD_LIBRARY_PATH: $SNAP/usr/lib/x86_64-linux-gnu/webkit2gtk-4.1/:$LD_LIBRARY_PATH
   #   "PYTHONPATH":  "$NAP/usr/lib/python3/dist-packages/"

hooks:
    install:
      plugs: [network]

Does this help ?

Hi, thanks for the quick reply. The fix suggested with private shared memory seemed promising.

I added it to snapcraft.yaml as follows:

plugs:
  shared-memory:
    private: true

This breaks the python app though, giving me the following error:

ERROR:aTrain.app:Exception on / [GET]
Traceback (most recent call last):
  File "/snap/atrain/x1/lib/python3.12/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/atrain/x1/lib/python3.12/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/atrain/x1/lib/python3.12/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/atrain/x1/lib/python3.12/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/atrain/x1/lib/python3.12/site-packages/aTrain/routes.py", line 30, in home
    languages = model_languages(default_model)
                                ^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'default_model' where it is not associated with a value

Anyone an idea how to solve this?