-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[BUG] ADDON service.libreelec.settings is messing with python asyncio event loop. #6431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Made some addons for testing over in a repo |
According to docs import asyncio
async def sleeper():
await asyncio.sleep(60)
print('#### tester 1 sleep finished')
loop = asyncio.get_running_loop()
loop.create_task(sleeper) |
On the other side, there is indeed a conflict if several addons try to run async tasks in an event loop. However, this is a general Kodi problem not specific to LibreELEC. I guess the reason is the way how addons are run using sub-interpreters and probably can be fixed only on Python level. |
I have confirmed that this is a Python problem related to the use of sub-interpreters. The following code produces the same error outside Kodi and LE: #include <iostream>
#include <thread>
#include <string>
#include "Python.h"
const std::string pyCode = R"""(
import asyncio
import threading
async def coro():
await asyncio.sleep(3)
print(f'Sleep in thread {threading.get_ident()} done')
asyncio.run(coro())
)""";
void runPython() {
PyThreadState* ts = PyThreadState_New(PyInterpreterState_Main());
PyEval_RestoreThread(ts);
PyThreadState* interpTs = Py_NewInterpreter();
PyRun_SimpleString(pyCode.c_str());
PyObject* error = PyErr_Occurred();
if (error) {
PyErr_PrintEx(0);
}
Py_EndInterpreter(interpTs);
PyThreadState_Swap(ts);
PyEval_ReleaseThread(ts);
}
int main(int argc, char *argv[]) {
Py_Initialize();
Py_BEGIN_ALLOW_THREADS
std::thread thread1(runPython);
std::thread thread2(runPython);
thread1.join();
thread2.join();
Py_END_ALLOW_THREADS
Py_Finalize();
std::cout << "All done" << std::endl;
return 0;
} |
As it turned out, it is known Python issue python/cpython#91375 that has no fix so far. The only possible workaround is to use a pure-Python implementation of asyncio event loop by disabling its C-based implementation. It can be done adding the following code at the top of your addon entrypoint: import sys
sys.modules['_asyncio'] = None |
Closing as completed - noting upstream closure. If still an issue please reopen or reference this issue. |
Describe the bug
ADDON service.libreelec.settings is messing with python asyncio event loop.
To Reproduce
Informations
Log file
A similar offending ADDON
service.asyncio.loop, which will claim and start it:
What I really wanted to do :)
service.aiohttp.server, will get never get any loop :(
And it becomes all messy as the event-loop already stolen here:
https://github.com/LibreELEC/service.libreelec.settings/blob/master/resources/lib/dbus_utils.py#L127
Possible solution:
The text was updated successfully, but these errors were encountered: