According to https://groups.google.com/d/msg/cefpython/NJUDIm81D3A/eBvHwJprCgAJ
it is the "debug" option that was causing the delays.
CEF Python writes to "debug.log" file using its own logger, however at the same time CEF is also writing to that same file. Maybe there is some conflict, something to do with lock acquired on the file, I don't know. Maybe CEF Python should use CEF log mechanism and that would fix it. It sounds like this is the cause. Here is the code in DebugLog.h:
FILE* pFile = fopen(g_logFile.c_str(), "a");
fprintf(pFile, "[CEF Python] App: %s\n", szString);
fclose(pFile);
It opens and closes the file for each single log write. It might be that CEF that also writes to this file,
opens it during cef initialization, acquires some lock and closes it at shutdown.
UPDATE:
When calling Python function from Javascript there is a stuttering of CSS animation during the time of the call. It looks like the UI thread is being locked for a moment. Reported on the Forum: https://groups.google.com/d/topic/cefpython/NJUDIm81D3A/discussion
At the end of this post there is presented a temporary solution that could be used for now, and two possible real solutions.
This looks like a GIL issue. GIL is a global interpreter lock in Python. Information found on the web:
Note that acquiring the GIL is a blocking thread-synchronising operation, and therefore potentially costly. It might not be worth releasing the GIL for minor calculations. Usually, I/O operations and substantial computations in parallel code will benefit from it.
Looks like the issue in question is only a momentary lock of the UI thread while acquiring GIL. Python <> Javascript calls are asynchronous, use IPC messaging between processes. Javascript runs in the renderer process, while Python runs in the browser process. You can execute time intensive tasks in Python using multiprocessing or similar, while not blocking the UI.
I recall a similar issue of UI locking when OnBeforePopup is being called in wxpython.py, in which a task is being posted on the UI thread to create a popup window.
Related information:
This are the steps during communication from Javascript to Python:
Things to consider:
There is an alternative for js<>py communication, from README.md:
For native communication between javascript and python use javascript bindings. Another option is to > run an internal python web server and use websockets/XMLHttpRequest for js<>python communication.
Using web server and XHR for communication wouldn't require any acquiring/releasing GIL, thus the issue should disappear I think.
Solution 1 (multi threaded message loop)UPDATE: This improves UI locking when calling js callbacks from Python, but there is still some GUI locking when calling Python func from javascript. It seems that the final solution would need to be to use multi threaded message loop along with implementing Python-native IPC messaging with the renderer processes, without the Chromium/CEF IPC layer so that GIL doesn't need to be acquired when receiving messages (Solution 2).
If it turns out this is a Windows-only problem, then I think that there is an alternative solution, to use ApplicationSettings.multi_threaded_message_loop (Issue #133). Message loop will run in a separate thread and any calls to Python won't block UI. However whether this would also resolve issue with GIL acquiring lock taking much time, I don't know, but for sure it won't lock UI (css animation). I haven't yet played with multi threaded message loop, so don't know how this would affect current code base. There may be some issues that would need to be resolved.
Solution 2 (Python-native IPC messaging with the renderer process)I think that it should be doable to avoid using CEF/Chromium inter-process messaging. If the issue is the GIL and we can get rid of the GIL being acquired when calling from CEF C++ function into Python in the browser process, then it should solve the UI lock issue.
We could handle IPC messaging in the browser process, directly with Python. In the renderer process we would need some cross-platform C++ code. Googled "python ipc c++" and found zeromq library that allows for sending IPC messages and can connect with any language.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4