Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaked semaphore object warning #4132

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

rodja
Copy link
Member

@rodja rodja commented Dec 21, 2024

This pull request fixes #4131: a "leaked semaphore object" warning appears when aborting with CTRL-C in certain configurations. Semaphores are used internally in multiprocessing.Queue which never get cleaned up properly.

Scenario 1: pressing CTRL-C in an FastAPI app stared via uvicron from the command line with auto-reloading

Because the multiprocessing.Queue objects in native.py have been created globally they where also instantiated when not in native mode. This PR fixes this by only creating the objects when native mode is activated.

Scenario 2: pressing CTRL-C when using ui.run(native=True, reload=True)

This is still unsolved. I verified that the shutdown/cleanup function for the Queue objects are correct. But the it seems that the pywebview window produces also leaked semaphores when pressing CTRL-C.

this avoids leaked semaphore objects when running a FastAPI app with uvicorn
@rodja rodja added the bug Something isn't working label Dec 21, 2024
@rodja rodja added this to the 2.10 milestone Dec 21, 2024
@rodja
Copy link
Member Author

rodja commented Dec 22, 2024

Pressing CTRL-C when using ui.run(native=True, reload=True) still shows the leaked semaphore object warning. I verified that the shutdown/cleanup function for the Queue objects are correct. But it seems that the pywebview window produces also leaked semaphores when pressing CTRL-C. I could not figure out a way to avoid it. Is anyone able to jump in?

@rodja
Copy link
Member Author

rodja commented Dec 31, 2024

It seems the leaked semaphores warning which appears with Native Mode is caused by something internal when pywebviews webview.start is being shut down. I suggest to ignore this for the current pull request.

@rodja rodja marked this pull request as ready for review December 31, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leaked Semaphore Objects
1 participant