diff --git a/cefpython/cef3/wx-subpackage/examples/sample2.py b/cefpython/cef3/wx-subpackage/examples/sample2.py index 62a258b7..ef8baa04 100644 --- a/cefpython/cef3/wx-subpackage/examples/sample2.py +++ b/cefpython/cef3/wx-subpackage/examples/sample2.py @@ -11,6 +11,8 @@ import wx import wx.lib.agw.flatnotebook as fnb import cefpython3.wx.chromectrl as chrome +import platform +import sys ROOT_NAME = "My Locations" @@ -32,6 +34,14 @@ def __init__(self): self.initComponents() self.layoutComponents() self.initEventHandlers() + if len(sys.argv) == 2 and sys.argv[1] == "test-launch": + wx.CallLater(500, self.testLaunch) + + def testLaunch(self): + # This hash is checked by /tests/test-launch.sh script + # to detect whether CEF initialized successfully. + print("b8ba7d9945c22425328df2e21fbb64cd") + self.Close() def initComponents(self): self.tree = wx.TreeCtrl(self, id=-1, size=(200, -1)) @@ -73,8 +83,16 @@ def OnPageClosing(self, event): def OnClose(self, event): self.Destroy() + if __name__ == '__main__': chrome.Initialize() + if platform.system() == "Linux": + # CEF initialization fails intermittently on Linux during + # launch of a subprocess (Issue 131). The solution is + # to offload cpu for half a second after Initialize + # has returned (it still runs some stuff in its thread). + import time + time.sleep(0.5) print('sample2.py: wx.version=%s' % wx.version()) app = wx.PySimpleApp() MainFrame().Show() diff --git a/cefpython/tests/test-launch.sh b/cefpython/tests/test-launch.sh new file mode 100755 index 00000000..16d247aa --- /dev/null +++ b/cefpython/tests/test-launch.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Usage: ./test-launch.sh 500 + +# When launching this test script more than once in current +# Linux session then the CEF initialization issue is hard +# to reproduce. The best results are when launching tests +# in a clean Ubuntu session, just log out and log in again, +# and run the test immediately. You could also run a few +# terminal sessions with several test scripts running +# simultaneously to simulate heavy overload. + +for ((i = 1; i <= $1; i++)); do + output=$(python ./../cef3/wx-subpackage/examples/sample2.py test-launch) + code=$? + if [[ $code != 0 || $output != *b8ba7d9945c22425328df2e21fbb64cd* ]]; then + echo "EXIT CODE: $code" + echo "OUTPUT: $output" + echo "ERROR!" + read -p "Press ENTER to exit" + exit $code + fi + echo RUN $i OK +done + +echo TEST SUCCEEDED +read -p "Press ENTER to exit"