Native mode, but packaged/frozen #1714
Replies: 4 comments 3 replies
-
That is strange. Have you tried the same app with pyinstaller? Does the problem also occurs there? |
Beta Was this translation helpful? Give feedback.
-
I had some time to look into the problem in some more detail, but did not try with pyinstaller yet. Adjusting the open_window function def open_window(
host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool,
method_queue: mp.Queue, response_queue: mp.Queue, **kwargs
) -> None:
while not helpers.is_port_open(host, port):
time.sleep(0.1)
window_kwargs = {
'url': f'http://{host}:{port}',
'title': title,
'width': width,
'height': height,
'fullscreen': fullscreen,
'frameless': frameless,
**kwargs
# **globals.app.native.window_args, <- remove
}
window = webview.create_window(**window_kwargs)
closed = Event()
window.events.closed += closed.set
start_window_method_executor(window, method_queue, response_queue, closed)
webview.start(storage_path=tempfile.mkdtemp(), **globals.app.native.start_args) and the mp Process call in the activate function to def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:
def check_shutdown() -> None:
while process.is_alive():
time.sleep(0.1)
globals.server.should_exit = True
while globals.state != globals.State.STOPPED:
time.sleep(0.1)
_thread.interrupt_main()
if 'native' not in globals.optional_features:
globals.log.error('Native mode is not supported in this configuration.\n'
'Please run "pip install pywebview" to use it.')
sys.exit(1)
mp.freeze_support()
args = host, port, title, width, height, fullscreen, frameless, native.method_queue, native.response_queue
process = mp.Process(target=open_window, args=args, kwargs=globals.app.native.window_args, daemon=False) # <- add kwargs directly to the Process call
process.start()
Thread(target=check_shutdown, daemon=True).start() works and the app.native.window_args are carried over as expected. Thus it seems to be a multiprocessing issue even more. Moreover the mp.freeze_support() might be out of place, at least if i read the multiprocessing docs correctly (?!):
Maybe someone with more experience can make some sense out of it. @rodja Are you 100% sure the way the nicegui.globals module is used works for the native mode window args? |
Beta Was this translation helpful? Give feedback.
-
Yes, from the documentation it looks wired. I remember vaguely that it still was necessary to ensure the window is closing properly when I worked on #917.
Yes. from nicegui import app, ui
ui.label('Hello Frameless World!')
app.native.window_args['frameless'] = True
app.native.window_args['confirm_close'] = True
ui.run(native=True, reload=False) |
Beta Was this translation helpful? Give feedback.
-
Hi there, I am being impacted by this very issue but without the need of compiling or freezing the code (just running with |
Beta Was this translation helpful? Give feedback.
-
Question
Hey,
prior to opening an issue i wanted to ask my question here, as it might be a simple error of mine. I am packaging a
an application with nicegui frontend using the
shiv
package. This is essentially the same as pyinstaller, i.e. zipping the site-packages of the venv, so maybe someone has an idea how to solve my problem.As the problem only occurs after packaging, there is no easy way to reproduce the issue (needs shiv configs and so on..), so i try my best to explain. I have code as shown below with additional pywebview arguments, e.g. 'confirm_close', and a function to be run 'on_startup'.
If I execute the below code directly from my IDE this works, but after packaging the application the window_args and on_startup are not used. I dug into the nicegui source code to see what reaches the window_open() function and confirmed that the window_args reaching the pywebview call are empty.
I suppose this is something caused by the multiprocessing setup, but i am kind of stuck there..
Thanks for any ideas :)
Fabian
Beta Was this translation helpful? Give feedback.
All reactions