In the next couple of weeks a PR will go into kodi that keeps python sessions open as long a user navigates inside an addon.
Reason is that this pushes performance significantly because modules are taken from python cache instead reloading / rereading them on every click.
From development side this means: Only the default python script (defined in addon.xml. commonly default.py or addon.py) are re-interpreted on every click.
All imported (sub-) modules will be taken from cache and not reinterpreted.
What does this mean for you python addon dev?
- arguments passed from kodi to addon are only available in default script, if you need them in any of your submodule script you either pass the current arguments from default script into your submodules, or you call sys.argv inside your functions where the code is executed. Storing the value of sys.arg[#] in a global variable at the head of your submodule will not work because the code is only executed once on first module startup, but not on subsequent calls.
- For compatibility reasons sys.argv[0] (base_url) and sys.argv[1] (plugin_handle) stay same when reused. This means that it is possible now to store them in a global variable in submodules.
- if you are debugging / developing a submodule, you may have to first select an other addon and then return to your addon to get a fresh reload. Or switch reusing of python session off (see below)
Reusing of python sessions can be disabled in addon.xml, metadata section:
xml:
<extension point="xbmc.addon.metadata">
<reuselanguageinvoker>false</reuselanguageinvoker>
</extension>
Edit: Pull Request:
https://github.com/xbmc/xbmc/pull/13814