Repository: zauberzeug/nicegui

Issue #1841: Runtime Error when trying to run native=True
Created: 2023-10-19T20:46:50Z
Description
I'm getting a Fork vs Spawn error when attempting to run a native app on Ubuntu.
Sample Application (from documentation)
from nicegui import app, ui

app.native.window_args['resizable'] = False
app.native.start_args['debug'] = True

ui.label('app running in native mode')
ui.button('enlarge', on_click=lambda: app.native.main_window.resize(1000, 700))

ui.run(native=True, window_size=(400, 300), fullscreen=False)
Invoked from command line from within a virtual environment:  python main.py
Trackback
Traceback (most recent call last):
  File "/mnt/ext3tbdrive/sandbox/try-nicegui/main.py", line 15, in <module>
    main()
  File "/mnt/ext3tbdrive/sandbox/try-nicegui/main.py", line 11, in main
    ui.run(native=True, window_size=(400, 300), fullscreen=False)
  File "/mnt/ext3tbdrive/sandbox/try-nicegui/env/lib/python3.11/site-packages/nicegui/run.py", line 180, in run
    ChangeReload(config, target=globals.server.run, sockets=[sock]).run()
  File "/mnt/ext3tbdrive/sandbox/try-nicegui/env/lib/python3.11/site-packages/uvicorn/supervisors/basereload.py", line 49, in run
    self.startup()
  File "/mnt/ext3tbdrive/sandbox/try-nicegui/env/lib/python3.11/site-packages/uvicorn/supervisors/basereload.py", line 85, in startup
    self.process.start()
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
                  ^^^^^^^^^^^^^^^^^
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/context.py", line 288, in _Popen
    return Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
  File "/home/tim/.pyenv/versions/3.11.6/lib/python3.11/multiprocessing/synchronize.py", line 107, in __getstate__
    raise RuntimeError('A SemLock created in a fork context is being '
RuntimeError: A SemLock created in a fork context is being shared with a process in a spawn context. This is not supported. Please use the same context to create multiprocessing objects and Process.

OS: Ubuntu 20.04
Python: 3.11.6
Pyenv: 2.3.29-5-g62e2e9c7
nicegui: 1.3.17
pywebview: 4.3.3

Duplicate issue #3815: Native mode error on Ubuntu
Created: 2024-09-30T16:03:43Z
Description
While working on an app that some people in our community center prefer to feel like an "application" instead of a page in the browser I tried to change it to native mode.
I ran it and I got this suggestion:
Native mode is not supported in this configuration. Please run "pip install pywebview" to use it.
I installed pywebview(it installed 5.2 which seems to be the latest), ran the app again and I ran into this error:
RuntimeError: A SemLock created in a fork context is being shared with a process in a spawn context. This is not supported. Please use the same context to create multiprocessing objects and Process.

I created a new file to test a minimal NiceGUI app with this:
from nicegui import ui

ui.button("test")

ui.run(native=True)
But I get the exact same error running this.
I'm using Python 3.12 .3 with NiceGUI 2.2.0(in a venv) on Ubuntu 24.0.4.1.
Any idea if this SemLock is something internal that's being funky when using native mode?
I don't believe this is related to #3813

Closing comment (2024-10-01T05:33:07Z): It is same as #1841