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

cef hangs while resizing in certain conditions #484

Closed
MarkusFF opened this issue Mar 13, 2020 · 23 comments
Closed

cef hangs while resizing in certain conditions #484

MarkusFF opened this issue Mar 13, 2020 · 23 comments
Labels

Comments

@MarkusFF
Copy link
Contributor

@MarkusFF MarkusFF commented Mar 13, 2020

Specification

  • pywebview version: 3.2
  • platform / version: Win7 Pro SP1
  • cefpython3 version 66.0

Description

Observed reproducible hang during use of cef gui, if triggering some kind of update while resizing the window. Minimally this code usually (but not 100% of the time) hangs on my machine:

import webview
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def reload_and_resize():
    window.evaluate_js("location.reload()")
    window.resize(1000, 420)
webview.start(reload_and_resize, gui="cef")

or while manually resizing something more like this:

import webview,time
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def keep_reloading():
    while True:
        time.sleep(1)
        window.evaluate_js("location.reload()")
webview.start(keep_reloading, gui="cef")

This may be a cefpython issue.

@MarkusFF
Copy link
Contributor Author

@MarkusFF MarkusFF commented Mar 13, 2020

Could be this: cztomczak/cefpython#464

@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Mar 22, 2020

I have reproduced it and it looks like a race condition issue to me. At least adding a debug print statement somewhere in an execution chain seem to eliminate the problem. I will look into it.

@github-actions
Copy link

@github-actions github-actions bot commented Apr 22, 2020

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Apr 22, 2020
@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 22, 2020

I have reproduced it and it looks like a race condition issue to me. At least adding a debug print statement somewhere in an execution chain seem to eliminate the problem. I will look into it.

Is there any news?

@r0x0r r0x0r removed the stale label Apr 23, 2020
@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Apr 23, 2020

I gave it a try, but did not make any progress. The problem is that as soon as I add any debugging statements, the problem is gone. For example

This hangs

import webview
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def reload_and_resize():
    window.evaluate_js("location.reload()")
    window.resize(1000, 420)
webview.start(reload_and_resize, gui="cef")

This does not

import webview
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def reload_and_resize():
    window.evaluate_js("location.reload()")
    print('w00t')
    window.resize(1000, 420)
webview.start(reload_and_resize, gui="cef")

Similarly adding print statements elsewhere in the CEF code eliminates the problem. Breakpoints set in sub threads are not invoked either. A dumb solution would be add a short sleep noop.

The second example in the original post did not result in hanging on my machine.

@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 23, 2020

This problem is fixed in cefpython repo in dev branch (I hope so), but I had no luck in building it on Win 10 so I made changes to cef.py here in pywebview

#add inner window hwnd to Browser class
class Browser:
    def __init__(self, window, handle, browser):
        ...
        self.inner_hwnd = self.browser.GetWindowHandle()
        ...

# resize through win api
@_cef_call
def resize(width, height, uid):
    instance = instances[uid]
    win32gui.SetWindowPos(instance.inner_hwnd, 0, 0, 0, width-16, height-38, win32con.SWP_NOZORDER | win32con.SWP_NOMOVE | win32con.SWP_NOACTIVATE)
    instance.browser.NotifyMoveOrResizeStarted()

width-16, height-38 is a temporary solution to not let inner window become bigger than outer and content on the sides not visible

@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Apr 23, 2020

@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 23, 2020

Have you tested if this fixes the problem?

Not a single hang after this patch, tried to resize window with mouse in different ways for a long time.
Your sample that hangs also not hanging

@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Apr 23, 2020

@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 23, 2020

Ok I'll try, but this is temporary solution until cefpython release 66.1 version (after that Browser.SetBounds method will be available on Win and we should use it to resize window)

ikhz added a commit to ikhz/pywebview that referenced this issue Apr 23, 2020
ikhz added a commit to ikhz/pywebview that referenced this issue Apr 23, 2020
@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 23, 2020

#504

@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Apr 27, 2020

@MarkusFF Can you verify if @ikhmyz PR fixes this problem for you?

@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 28, 2020

@MarkusFF Can you verify if @ikhmyz PR fixes this problem for you?

Actual PR contains code using ctypes windll instead of win32gui as you suggested and it still hangs, need to check it and if the problem reproduced check win32gui version then.

@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Apr 30, 2020

@ikhmyz Would you share an example that results in a hanging? I could not reproduce it with this code

import webview
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def reload_and_resize():
    window.evaluate_js("location.reload()")
    window.resize(1000, 420)
webview.start(reload_and_resize, gui="cef")

@MarkusFF
Copy link
Contributor Author

@MarkusFF MarkusFF commented Apr 30, 2020

I'll try it out.

@MarkusFF
Copy link
Contributor Author

@MarkusFF MarkusFF commented Apr 30, 2020

I've checked out and installed ikhmyz:win_cef_resize_hang. I didn't manage to crash either of my minimal examples, nor the app I observed the problem in the first place. Seems like it works!

(at 4b53046)

@ikhz
Copy link
Contributor

@ikhz ikhz commented Apr 30, 2020

@ikhmyz Would you share an example that results in a hanging? I could not reproduce it with this code

import webview
window=webview.create_window('Hello world', html='<h1>hello</h1>')
def reload_and_resize():
    window.evaluate_js("location.reload()")
    window.resize(1000, 420)
webview.start(reload_and_resize, gui="cef")

Dont have acces to Windows machine right now. It hangs when you resize the window with mouse very fast in random directions, not programatically with window.resize()

@NiceneNerd
Copy link

@NiceneNerd NiceneNerd commented May 23, 2020

I'm also having problems with CEF windows hanging if resized with the mouse. Usually it only happens when there is background activity on the Python end. Same on Windows 10 Home and Windows Server 2019.

@ikhz
Copy link
Contributor

@ikhz ikhz commented May 23, 2020

I'm also having problems with CEF windows hanging if resized with the mouse. Usually it only happens when there is background activity on the Python end. Same on Windows 10 Home and Windows Server 2019.

Maybe it is the reason, I had another thread with socketio running when it happened.

@ragods
Copy link

@ragods ragods commented May 26, 2020

url = 'http://localhost'
dsize = ctypes.windll.user32
window = webview.create_window('title', url, js_api=api, fullscreen=True, min_size=(dsize.GetSystemMetrics(0), dsize.GetSystemMetrics(1)))

r0x0r pushed a commit that referenced this issue Jun 2, 2020
@r0x0r
Copy link
Owner

@r0x0r r0x0r commented Jun 2, 2020

The pull request is merged into master. Can this be closed or are there any issues left?

@r0x0r r0x0r mentioned this issue Jun 27, 2020
@github-actions
Copy link

@github-actions github-actions bot commented Jul 3, 2020

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Jul 3, 2020
@MarkusFF
Copy link
Contributor Author

@MarkusFF MarkusFF commented Jul 7, 2020

Thanks!

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

5 participants