-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
Deadlock while closing the window with persistent threads running #138
Comments
Hm, looks like this is an issue we should solve internally, rather than exposing I think the cleanup-call feature is more plausible, especially in the later context. BTW to check if the app is still running on Cocoa, you can use the |
That would be great. Any thoughts of the equivalent call for WinForms? |
Roman does all Windows coding so I don't know much about it :) Nevertheless, |
The deadlock must certainly be fixed, but I don't feel there is a need for a public window_exists function (unless multi-window functionality materializes). A better approach would be to catch windowWillClose/OnDestroy/etc event on each platform and a set a semaphore there, evaluate_js would acquire the semaphore and would check for the existence of the window before executing javascript code. |
I just noticed, in its current shape, the multi-window code automatically handles Setting a new semaphore would need adding it to all the API methods, right? |
@shivaprsdv, Any thoughts on the best path forward for this one? I have a single-window application, but should I use the multi-window branch simply for this behavior? Currently there is no elegant way to quit a program with persistent threads running. |
The deadlocks are caused by semaphores that doesn't get released if we call stop on the NSApp. The fix is to acquire semaphores only if app is running, and manually release blocked ones (if any) before stopping the main loop.
I have confirmed that we have indeed hit a bug here. This occurs on all platforms @pomplesiegel Feel free to experiment with the |
Great, i'll give the multi-window a shot. Thanks! |
@shivaprsdv, I just tested your branch "deadlock-fix" and it fixed my thread problem for quitting the program! Great work. |
Great, thanks. 🙂 But I should say it's likely to be only a temporary fix. For the problem seems to |
I have pushed a similar solution for WinForms to the deadlock-fix branch. Good to merge? |
Don't think so; we haven't had a solution to the problem on Linux yet. Moreover, I don't think this approach would fix it for sure. I'm studying it in |
Okay, I have pin-pointed the issue. It is two fold:
Ideally, such calls should be blocked in the init file itself. This benefits all the Keeping this in mind, I have redone the work on this issue: you can find it in I've also added a tentative commit for Winforms based on your last commit, |
Closes #138 The deadlocks are caused by semaphores that don't get released once the webview is closed. Solution: * Block API calls once the webview is closed, in the init script itself. * After stopping the main loop, manually release semaphores if needed. Note: I've added an internal is_running() method to check if the webview has been closed. If the multi-window branch gets merged in the future, this will become obsolete, and should be removed.
@shivaprsdv, great. so far this is working well on Mac. Any reason not to expose |
Nothing particular. As I mention in the above commit message, try:
webview.evaluate_js()
# webview is running
except:
# webview is not running |
Great, that's what I'm doing now. Thanks! |
@pomplesiegel Can you test the |
Hello @shivaprsdv, sorry for the delay! I have tested both branches and am currently running the deadlock-fix-alt branch in my program. It's behaving very well! I have tested on both mac and windows. I will continue testing. |
@shivaprsdv Looks good. Would you make a PR? |
When updating the DOM from a separate thread, using calls like
webview.evaluate_js()
I found it quite useful to have an API call which indicates whether the window is still present / attempting to close.Problem
If one clicks the close button on a window (rather than quitting it like with Apple + Q), and then a separate thread calls to the webview object, like
webview.evaluate_js()
, this thread becomes blocked and stuck in that call indefinitely.What would be helpful is a function like
webview.window_exists()
which returns a boolean, which is set within
WindowDelegate::windowWillClose_()
(and the equivalent location on other platforms). I tested this by adding a global variable to cocoa.py which is set withinwindowWillClose_
, and havingwebview
return the status of this boolean. Certainly not the cleanest way, but it works.Could we perhaps integrate this in a more OO-friendly fashion. I'm happy to help.
Alternatively, we could provide an API for a callback function, which would be called (in addition to the window closing) when the user hits the "x" or close button on a window. A sort-of cleanup call, to prevent deadlock.
Thoughts?
Thanks!
Michael
The text was updated successfully, but these errors were encountered: