-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
[Windows] Crash on exit with multi_threaded_message_loop=True #380
Comments
…message_loop=True
Related PR: #412 |
Is a workaround available? Even after following the correct browser close-and-dereference procedures, cef.Shutdown() still crashes the application, but yields neither an exception nor a stack trace. A minimal example of the problem code: import sys
import time
from cefpython3 import cefpython as cef
test_browser = None
def main():
sys.excepthook = cef.ExceptHook
cef.Initialize(
settings={'multi_threaded_message_loop': True},
switches={'enable-logging': '',
'v': '1'}
)
cef.PostTask(cef.TID_UI, create_test_browser)
time.sleep(5.0)
cef.PostTask(cef.TID_UI, close_test_browser)
try:
print('Trying cef.Shutdown()')
cef.Shutdown()
finally:
print("Post-Shutdown code") # Execution never reaches this point.
def create_test_browser():
assert cef.IsThread(cef.TID_UI)
global test_browser
test_browser = cef.CreateBrowserSync(
cef.WindowInfo(),
{},
'data:text/html,<!DOCTYPE html><html><body>Hello World!</body></html>'
)
def close_test_browser():
assert cef.IsThread(cef.TID_UI)
global test_browser
test_browser.CloseBrowser()
test_browser = None
print('Test browser closed')
if __name__ == '__main__':
main() And the resulting log (verbose level 1):
The exit code corresponds to Exception code: 0x80000003. This issue has been discussed on the CEF Forum. However, the workaround proposed (equivalent to adding My specs:
Let me know if I can answer any further questions. Thank you for your time. |
@MikeChurvis Your logs don't make sense, Shutdown is being called before "Trying cef.Shutdown" is printed. |
@cztomczak New discovery: The error still occurs when no browser is created. New minimal example: import sys
from cefpython3 import cefpython as cef
def main():
sys.excepthook = cef.ExceptHook
cef.Initialize(
settings={
'multi_threaded_message_loop': True},
switches={
'enable-logging': '',
'v': '1'
})
print('Initialize complete.')
cef.Shutdown()
print('Shutdown complete.')
if __name__ == '__main__':
main() The log:
Now I'm truly stumped. What are your thoughts? |
Shutdown seems to be called too early. Your logs are again out of order. |
@cztomczak I added a 10 second sleep between
|
Looks like a breakpoint. See https://stackoverflow.com/questions/11583957/program-has-exited-with-code-2147483645 You would need to debug using Visual Studio. You can download CEF debug symbols from Spotify automated builds site. Looks like a breakpoint in Chromium/CEF code. |
The script runs fine for me without any errors. Are you using a custom built Python or cefpython? My logs:
|
Tested with Python 3.6.8. |
No. I'm using Anaconda's Python 3.7.4 interpreter, and for cefpython, it was just I will try the example with a fresh venv & clean Python 3.6.8 install. |
@cztomczak No luck. Fresh Python 3.6.8 install, new pipenv. Same exact error & log as before. I'm running low on time for this deliverable, so I'm gonna have to bite the bullet & restructure the app to be able to use cef.MessageLoop() on the main thread. This wasn't possible with pystray, so I'll have to find an alternative. That said, if I have some time afterwards, I'd love to learn how to debug these kinds of deep errors! You mentioned using VS and Spotify's debug symbols; is there a good resource for learning how to setup something like that? |
What if you call cefpython/examples/wxpython.py Line 219 in 5c15c72
|
No statement after |
You should be able to debug with any Visual Studio. Last time I've debuged cefpython with VS2017. First download libcef.dll.pdb with release symbols (win, 64bit): Place it next to libcef.dll in the cefpython3 package directory. Launch python script, then click the Attach to process button in top bar and select options as seen on the screenshot (Native code, Python code). To debug cefpython code you would need to modify cefpython build scripts to add debug flags so that debug symbols are included and then build it from sources. |
In the attach to process window select python.exe process and also subprocess.exe - there are multiple of them, these are Chromium subprocesses. |
@cztomczak Wonderful! Thank you so much for your help and guidance on this. I'll let you know what I find! |
Patch available in PR #412.
Do not call CefDoMessageLoopWork in cef.Shutdown() when multi_threaded_message_loop=True. This is probably the cause of a crash in pywin32.py example (PR #374) when using multi threaded message loop.
To fix this, modifications in cefpython.pyx are required, so that message loop work calls are not executed during shutdown when multi threaded message loop is set to true. PRs are welcome.
The text was updated successfully, but these errors were encountered: