-
-
Notifications
You must be signed in to change notification settings - Fork 729
Leaked Semaphore Objects #4131
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
Comments
@falkoschindler do you remember why 942e5e4 reverted the fix #4132? |
On version
|
For me it is the same and I synthesized just to the import import nicegui
import time
import sys
import os
print('SLEEP FOR STOP')
time.sleep(3)
print('RESTART')
python = sys.executable
os.execv(python, ['python'] + sys.argv) If you comment out the
Just run by |
It seems to be an issue while using multiprocessing Queue This is eneough to get leaked memory: import time
import sys
import os
from multiprocessing import Queue
q = Queue()
print('SLEEP FOR STOP')
time.sleep(1)
print('RESTART')
python = sys.executable
os.execv(python, ['python'] + sys.argv) if change the line to q = None no issue :-( |
If someone is interested in going deeper, I realized that the issue raises when file: multiprocessing/resource_tracker.py [183] def _send(self, cmd, name, rtype):
...
msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii')
...
nbytes = os.write(self._fd, msg) If I drop the message like: msg = b'' no leak exist.
file: multiprocessing/util.py [451] _posixsubprocess.fork_exec(
args, [path], True, passfds, None, None,
-1, -1, -1, -1, -1, -1, errpipe_read, errpipe_write,
False, False, -1, None, None, None, -1, None,
subprocess._USE_VFORK) for args:
and path:
I am running on OSX with python 3.12.7 Not sure how to proceed here ? @falkoschindler - any suggestions ? |
GOTCHA :-) If you forward the process into a new one by The issue is solved by this: import time
import sys
import os
import multiprocessing
q = multiprocessing.Queue()
print('SLEEP FOR STOP')
time.sleep(1)
print('RESTART')
# important cleanup locks and semaphores
multiprocessing.util._exit_function()
python = sys.executable
os.execv(python, ['python'] + sys.argv) not sure if this may help some others here but for tokeo it sole my Kindly |
Looks promising, @TomFreudenberg! |
Hi @falkoschindler I will try a PR within the next couple of time. |
@TomFreudenberg Great!
Not that I'm aware of. |
@TomFreudenberg with c516d03 I put the fix into #4641 which needed it desperately. Due to changes in shutdown mechanics the "leaked semaphores" warning appeared in every app. |
Super @rodja, so I press my thumps that the PR is available soon. Thanks for fixing this as well. |
@falkoschindler I saw that you reverted the changes. Let me know if more effort is necessary afterwards. |
@TomFreudenberg Oh yes, we noticed that #4641 doesn't seem to introduce new semaphore problems, but the same warnings already happen on main. So there is no need to solve this problem in this very PR. And as it turned out, fixing the semaphore objects still needs some work (tests are not passing yet). So @rodja suggested to extract this topic from the PR. He can certainly give some more information about what needs to be done. |
Discussed in #4129
Originally posted by ChipsAHoai December 20, 2024
Question
I am having leaked semaphore issues when running nicegui with fastapi. Initially, I thought it was my code, however, I just tested this on Zauberzeug's repo running the start.sh bash script under examples/fastapi and immediately closed down the uvicorn server and it still shows leaked semaphores. Is there a solution for this?
Reproduction:
^CINFO: Shutting down
is the line where I press CTRL-C to abort the execution.It also happens when starting native mode and reloading:
Pressing CTRL-C yields also a leaked semaphore objects warning.
The text was updated successfully, but these errors were encountered: