问题描述
我构建了一个简单的Kivy应用程序,该应用程序在新窗口应用程序中启动了cefpython浏览器。只要我单击一次按钮并启动一个浏览器,该应用程序就可以正常运行。但是,当我单击同一按钮时,我想重复启动多个cefpython浏览器。这样做时,出现以下错误:
AssertionError: cefpython.CreateBrowserSync() may only be called on the UI thread
有时,应用程序崩溃并出现以下错误:
Trace/breakpoint trap (core dumped)
这是我的Python代码:
class SivaCEFBrowser(Screen):
def back_to_login(self):
App.get_running_app().root.current='login_screen'
App.get_running_app().root.transition.direction='right'
def go_to_verify(self):
App.get_running_app().root.current='verify_screen'
App.get_running_app().root.transition.direction='left'
def launch_cef_browser(self): # Use an additional parameter,'dt',if invoked using Clock.schedule_once().
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error.
cef.Initialize()
cef.CreateBrowserSync(url="https://www.google.com/",window_title="Hello World!")
#cef.CreateBrowser(url="https://www.google.com/",window_title="Hello World!")
cef.MessageLoop()
cef.Shutdown()
def trigger_browser(self):
#Clock.schedule_once(self.launch_cef_browser) # Starts in the same thread and pauses execution of Kivy code.
self.t=threading.Thread(target=self.launch_cef_browser)
self.t.start()
def close_browser(self):
print("Quit Message Loop")
cef.QuitMessageLoop()
这是我的Kivy代码:
<SivaCEFBrowser>:
name: 'cef_screen'
on_pre_enter: root.trigger_browser()
on_leave: root.close_browser()
canvas.before:
Color:
rgba: 195/255,60/255,35/255,1
Rectangle:
pos: self.pos
size: self.size
AnchorLayout:
id: cef_backbtn_layout
anchor_x: 'left'
anchor_y: 'top'
ImageButton:
id: cef_back_button
size_hint: 0.1,0.1
source: {'normal': 'images/chevron-left-96.png','down': 'images/chevron-left-96.png'} [self.state]
on_release: root.back_to_login()
AnchorLayout:
id: cef_forwardbtn_layout
anchor_x: 'right'
anchor_y: 'top'
ImageButton:
id: cef_forward_button
size_hint: 0.1,0.1
source: {'normal': 'images/chevron-right-96.png','down': 'images/chevron-right-96.png'} [self.state]
on_release: root.go_to_verify()
有人可以帮助我启动多个cefpython浏览器而不会导致Kivy应用崩溃吗?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)