Closed Pairman closed 1 month ago
multiprocessing
is mostly unsupported in the current version of Briefcase (https://github.com/beeware/briefcase-windows-VisualStudio-template/issues/8). However, there's probably a way to run your server in a thread instead of a separate process. See these StackOverflow questions for advice:
Closing on the basis that this is an issue with the support package/template, not Briefcase itself.
Describe the bug
I'm working on a project where it needs
aiohttp
to run a web server. It must be be ran in a main thread, so I have to put its logic under a daemon process withmultiprocessing.Process(target = ..., daemon = True)
.It totally works on Android, Ubuntu on Fedora, except Windows. My users on Windows have reported that they cannot access the web server with the built-in WebView nor their browsers, showing
ERR_CONNECTION_REFUSED
, which indicates that the web server isn't started properly.So I took a look into this using
briefcase dev
andbriefcase run -u
. If I usebriefcase dev
, the web broswer (or daemon process) can be started normally and can be accessed. However withbriefcase run -u
, my APP will be launched for multiple times indefinitely, resulting in a ton of windows, and the web server cannot be accessed. And if I remove themultiprocessing.Process(...).start()
, briefcase won't spawn me numerous windows. The.msi
frombriefcase package
won't spawn multiple windows, but as I said, its web server cannot be started normally too.I reproduced exactly these bugs in the following simplified setup. Note: The
daemon = True
formultiprocessing.Process
is not necessary for this bug to happen. And a simpletime.sleep()
in the daemon process also causes these bug.Hope this can be fixed. Thanks.
Steps to reproduce
multiprocessing.Process
along with the main GUI.briefcase run -u
, APP windows will be spawned non-stop. And the thing in the daemon process won't working properly..msi
frombriefcase package
, the thing in the daemon process won't working properly too.Expected behavior
briefcase run
shouldn't create multiple windows for my APP.briefcase run
or the installed package, on Windows.Screenshots
No response
Environment
OS: Windows-11-10.0.22631-SP0 AMD64 Python exe: C:\Users\Pairman\Downloads\bw\venv\Scripts\python.exe Python version: 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] Virtual env: True Briefcase: 0.3.19 Toga: toga-0.4.7 toga-core-0.4.7 toga-winforms-0.4.7
Logs
briefcase create
:briefcase run -u
(stopped with ctrl + c):Additional context
Simplified code to reproduce these bugs: