Skip to content

Commit 8d2c1e7

Browse files
committed
Improve fix for possible errors on shutdown (previous commit).
1 parent d9bbf7c commit 8d2c1e7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/cefpython.pyx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ g_debugFile = "debug.log"
118118
g_applicationSettings = {}
119119
g_commandLineSwitches = {}
120120

121+
_MessageLoopWork_wasused = False
122+
121123
cdef dict g_globalClientCallbacks = {}
122124

123125
# If ApplicationSettings.unique_request_context_per_browser is False
@@ -428,6 +430,10 @@ def MessageLoopWork():
428430
# GIL must be released here otherwise we will get dead lock
429431
# when calling from c++ to python.
430432

433+
if not _MessageLoopWork_wasused:
434+
global _MessageLoopWork_wasused
435+
_MessageLoopWork_wasused = True
436+
431437
with nogil:
432438
CefDoMessageLoopWork();
433439

@@ -448,13 +454,18 @@ def Shutdown():
448454
g_sharedRequestContext.Assign(NULL)
449455
Debug("Shutdown()")
450456
with nogil:
451-
CefShutdown()
452457
# Temporary fix for possible errors on shutdown. See this post:
453458
# https://magpcss.org/ceforum/viewtopic.php?p=30858#p30858
454459
# May be fixed by host owned message loop, see Issue 1805:
455460
# https://bitbucket.org/chromiumembedded/cef/issues/1805/
456-
for i in range(10):
457-
CefDoMessageLoopWork()
461+
if _MessageLoopWork_wasused:
462+
for i in range(10):
463+
CefDoMessageLoopWork()
464+
CefShutdown()
465+
if _MessageLoopWork_wasused:
466+
for i in range(10):
467+
CefDoMessageLoopWork()
468+
458469

459470

460471
def SetOsModalLoop(py_bool modalLoop):

0 commit comments

Comments
 (0)