pywebview: Deadlock while closing the window with persistent threads running

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 within windowWillClose_, and having webview 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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@shivaprsdv Looks good. Would you make a PR?

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.

Great, that’s what I’m doing now. Thanks!