Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62fffaf

Browse files
committed
Update Tutorial.md - move message loop topic more to the bottom
1 parent 078b953 commit 62fffaf

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

docs/Tutorial.md

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Table of contents:
1818
* [Hello world](#hello-world)
1919
* [Architecture](#architecture)
2020
* [Handling Python exceptions](#handling-python-exceptions)
21-
* [Message loop](#message-loop)
2221
* [Settings](#settings)
2322
* [Change user agent string](#change-user-agent-string)
2423
* [Client handlers](#client-handlers)
2524
* [Javascript integration](#javascript-integration)
2625
* [Javascript exceptions and Python exceptions](#javascript-exceptions-and-python-exceptions)
2726
* [Plugins and Flash support](#plugins-and-flash-support)
27+
* [Message loop](#message-loop)
2828
* [Off-screen rendering](#off-screen-rendering)
2929
* [Build executable](#build-executable)
3030
* [Support and documentation](#support-and-documentation)
@@ -151,73 +151,17 @@ sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
151151
See Python docs for [sys.excepthook](https://docs.python.org/2/library/sys.html#sys.excepthook).
152152

153153
The cef.ExceptHook helper function does the following:
154-
1. Calls cef.[QuitMessageLoop](../api/cefpython.md#quitmessageloop)
155-
2. Calls cef.[Shutdown](../api/cefpython.md#shutdown)
156-
3. Writes exception to "error.log" file
157-
4. Prints exception
154+
1. Writes exception to "error.log" file
155+
2. Prints exception
156+
3. Calls cef.[QuitMessageLoop](../api/cefpython.md#quitmessageloop)
157+
4. Calls cef.[Shutdown](../api/cefpython.md#shutdown)
158158
5. Calls [os._exit(1)](https://docs.python.org/2/library/os.html#os._exit) -
159159
which exits the process with status 1, without calling
160160
cleanup handlers, flushing stdio buffers, etc.
161161

162162
See CEF Python's ExceptHook source code in src/[helpers.pyx](../src/helpers.pyx).
163163

164164

165-
## Message loop
166-
167-
Message loop is a programming construct that waits for and
168-
dispatches events or messages in a program. All desktop GUI
169-
programs must run some kind of message loop. The hello_world.py
170-
example doesn't depend on any third party GUI framework and thus
171-
can run CEF message loop directly by calling cef.MessageLoop().
172-
However in other examples that embed CEF browser with GUI frameworks
173-
such as Qt/wxPython/Tkinter you can't call cef.MessageLoop(), because
174-
these frameworks run a message loop of its own. For such cases CEF
175-
provides cef.MessageLoopWork() which is for integrating CEF message
176-
loop into existing application message loop. Usually
177-
cef.MessageLoopWork() is called in a 10ms timer.
178-
179-
**Performance**
180-
181-
Calling cef.MessageLoopWork() in a timer is not the best performant
182-
way to run CEF message loop, also there are known bugs on some
183-
platforms when calling message loop work in a timer. There are two
184-
options to increase performance depending on platform. On Windows
185-
use a multi-threaded message loop for best performance. On Mac use
186-
an external message pump for best performance.
187-
188-
**Windows: multi-threaded message loop**
189-
190-
On Windows for best performance a multi-threaded message loop should
191-
be used instead of cef.MessageLoopWork() or external message pump. To do
192-
so, set ApplicationSettings.[multi_threaded_message_loop](../api/ApplicationSettings.md#multi_threaded_message_loop)
193-
to True and run a native message loop in your app. Don't call CEF's
194-
message loop. Create browser using `cef.PostTask(cef.TID_UI, cef.CreateBrowserSync, ...)`.
195-
Note that when using multi-threaded message loop, CEF's UI thread
196-
is no more application's main thread, and that makes it a bit harder
197-
to correctly use CEF API. API docs explain on which threads a function
198-
may be called and in case of handlers' callbacks (and other interfaces)
199-
it is stated on which thread a callback will be called. See also
200-
[Issue #133](../../../issues/133).
201-
202-
**Mac: external message pump**
203-
204-
CEF provides ApplicationSettings.[external_message_pump](../api/ApplicationSettings.md#external_message_pump)
205-
option for running an external message pump that you should use for
206-
best performance and to get rid of some bugs that appear when using
207-
cef.MessageLoopWork() in a timer.
208-
209-
This option is currently marked experimental as it wasn't yet fully
210-
tested. This option should work good on Mac - in upstream CEF it was
211-
tested mainly on Mac. If you've successfully used this option on Mac
212-
please let us know on the Forum.
213-
214-
**Linux**
215-
216-
External message pump option is not recommended to use on Linux,
217-
as during testing it actually made app x2 slower - it's a bug in
218-
upstream CEF. See [Issue #246](../../../issues/246) for more details.
219-
220-
221165
## Settings
222166

223167
CEF settings are provided in multiple ways. There are global
@@ -520,6 +464,62 @@ For the old CEF Python v31 release instructions for enabling Flash
520464
support are available on Wiki pages.
521465

522466

467+
## Message loop
468+
469+
Message loop is a programming construct that waits for and
470+
dispatches events or messages in a program. All desktop GUI
471+
programs must run some kind of message loop. The hello_world.py
472+
example doesn't depend on any third party GUI framework and thus
473+
can run CEF message loop directly by calling cef.MessageLoop().
474+
However in other examples that embed CEF browser with GUI frameworks
475+
such as Qt/wxPython/Tkinter you can't call cef.MessageLoop(), because
476+
these frameworks run a message loop of its own. For such cases CEF
477+
provides cef.MessageLoopWork() which is for integrating CEF message
478+
loop into existing application message loop. Usually
479+
cef.MessageLoopWork() is called in a 10ms timer.
480+
481+
**Performance**
482+
483+
Calling cef.MessageLoopWork() in a timer is not the best performant
484+
way to run CEF message loop, also there are known bugs on some
485+
platforms when calling message loop work in a timer. There are two
486+
options to increase performance depending on platform. On Windows
487+
use a multi-threaded message loop for best performance. On Mac use
488+
an external message pump for best performance.
489+
490+
**Windows: multi-threaded message loop**
491+
492+
On Windows for best performance a multi-threaded message loop should
493+
be used instead of cef.MessageLoopWork() or external message pump. To do
494+
so, set ApplicationSettings.[multi_threaded_message_loop](../api/ApplicationSettings.md#multi_threaded_message_loop)
495+
to True and run a native message loop in your app. Don't call CEF's
496+
message loop. Create browser using `cef.PostTask(cef.TID_UI, cef.CreateBrowserSync, ...)`.
497+
Note that when using multi-threaded message loop, CEF's UI thread
498+
is no more application's main thread, and that makes it a bit harder
499+
to correctly use CEF API. API docs explain on which threads a function
500+
may be called and in case of handlers' callbacks (and other interfaces)
501+
it is stated on which thread a callback will be called. See also
502+
[Issue #133](../../../issues/133).
503+
504+
**Mac: external message pump**
505+
506+
CEF provides ApplicationSettings.[external_message_pump](../api/ApplicationSettings.md#external_message_pump)
507+
option for running an external message pump that you should use for
508+
best performance and to get rid of some bugs that appear when using
509+
cef.MessageLoopWork() in a timer.
510+
511+
This option is currently marked experimental as it wasn't yet fully
512+
tested. This option should work good on Mac - in upstream CEF it was
513+
tested mainly on Mac. If you've successfully used this option on Mac
514+
please let us know on the Forum.
515+
516+
**Linux**
517+
518+
External message pump option is not recommended to use on Linux,
519+
as during testing it actually made app x2 slower - it's a bug in
520+
upstream CEF. See [Issue #246](../../../issues/246) for more details.
521+
522+
523523
## Off-screen rendering
524524

525525
Off-screen rendering, in short OSR, also known as windowless

0 commit comments

Comments
 (0)