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

Deadlock while closing the window with persistent threads running on Windows (again) #1439

Closed
gitillusion09 opened this issue Jul 20, 2024 · 7 comments
Labels

Comments

@gitillusion09
Copy link

Hello @r0x0r :)
When closing, the app keeps hanging forever.
I know there was already a similar issue back in 2017 (#138), but I think the fix does not work (anymore ?) on Windows 11.
I work with pywebview 5.1. I have a renderer thread that in some cases, calls the evaluate_js method periodically. If the application closes at this exact moment, and even though the thread has been joined, the app keeps hanging forever.
Does anyone have the issue on Windows?

I am not sure to have the skills to work on this issue myself...

@r0x0r
Copy link
Owner

r0x0r commented Jul 20, 2024

Do you happen to have a standalone example that would reproduce the bug?

@gitillusion09
Copy link
Author

gitillusion09 commented Jul 20, 2024

Yes, here you go: https://github.com/gitillusion09/pywebview-test

It is a basic (very basic) example but you got the idea. I took as reference your Serverless example, and tweaked it a bit to reproduce the bug: just launch it, the thread will start printing current date on the UI. When closing the app (with the window's cross), the app hangs on forever, even though I terminate the thread from the on_closing() method.

Thanks a lot for your time

@gitillusion09
Copy link
Author

gitillusion09 commented Jul 21, 2024

@r0x0r It seems to me that the following line should_cancel = self.closing.set() in the on_closing() method is what is blocking the app

@r0x0r
Copy link
Owner

r0x0r commented Jul 30, 2024

I modified event handler logic so that instead of launching a thread that is blocked via a semaphore, it executes event handlers synchronously. The fix concerns only the closing event. This fixes the problem in your example. The fix could be found in the master branch.

Another fix would be making your background thread daemon and getting rid of the join.

@gitillusion09
Copy link
Author

Thanks a lot for your fix ! Appreciate it :)

Copy link

github-actions bot commented Sep 3, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Sep 3, 2024
Copy link

github-actions bot commented Sep 8, 2024

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

@github-actions github-actions bot closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants