cztomczak / cefpython

Python bindings for the Chromium Embedded Framework (CEF)
Other
3.08k stars 473 forks source link

Crash on Linux after opening a window two times #635

Closed cptx032 closed 3 years ago

cptx032 commented 3 years ago

Hi! I'm running the following example:

from cefpython3 import cefpython as cef
import sys

sys.excepthook = cef.ExceptHook
cef.Initialize(
    None,
    {
        "ignore-certificate-errors": "",
        "disable-gpu": "",
    },
)
browser = cef.CreateBrowserSync(
    url="https://google.com", window_title="Title"
)
cef.MessageLoop()
cef.Shutdown()

# Opoening a new window again
cef.Initialize(
    None,
    {
        "ignore-certificate-errors": "",
        "disable-gpu": "",
    },
)
browser = cef.CreateBrowserSync(
    url="https://google.com", window_title="Title"
)
cef.MessageLoop()
cef.Shutdown()

The first browser opens normally, but after I close it manually, the second browser doesn't show up and I get in my terminal: Trace/breakpoint trap (core dumped). The same if I close programatically:

from cefpython3 import cefpython as cef
import sys
import threading
import time

sys.excepthook = cef.ExceptHook
cef.Initialize(
    None,
    {
        "ignore-certificate-errors": "",
        "disable-gpu": "",
    },
)
browser = cef.CreateBrowserSync(
    url="https://google.com", window_title="Title"
)

def close_in_thread():
    time.sleep(5)
    print("SHUTDOWN")
    cef.Shutdown()
threading.Thread(target=close_in_thread).start()

cef.MessageLoop()
cef.Shutdown()

cef.Initialize(
    None,
    {
        "ignore-certificate-errors": "",
        "disable-gpu": "",
    },
)
browser = cef.CreateBrowserSync(
    url="https://google.com", window_title="Title"
)
cef.MessageLoop()
cef.Shutdown()

Is that the correct way to close the browser, what I'm doing wrong?

cztomczak commented 3 years ago

You can initialize/shutdown CEF only once during app lifetime.

cptx032 commented 3 years ago

Ok! Thanks for the reply!