Addons and execution concurrency

I have received a bug report affecting to Advanced Emulator Launcher. The problem is related to the concurrent model used by Kodi tu run addons. Every time the user clicks on a menu, opens a context menu or launches a playable item, a new instance of the Python interpreter is created to run the addon. This is absolutely fine and I have trying to avoid concurrent-related problems in AEL by making AEL as blocking as possible (by using lot of progress dialogs, etc.). However, even a careful programmed addon has it limits and there are situations that this concurrency causes trouble. One example is the bug reported.

Another issue is the database corruption that plagued old good Advanced Launcher: roughly speaking, the problem was caused by two instances of AL writing at the same time to the file launchers.xml which completely destroyed the XML database. I have reduced this issue in AEL a lot with better programming practises but in theory has not completely disappeared. Yes, I know… I can use file locking mechanisms in order to avoid this problem but those are highly operating system dependant, non easily portable even in Python.

I would like to kindly ask the core developers to create a new Python API call like this

Code:
xbmcplugin.numRunningInstances()

OR

xbmcaddon.numRunningInstances()

that will return 1 if the current instance is the only one running or >= 1 if there are more than one instance running concurrently at the time of instantiating the addon. With a call like this I can make AEL to ensure never to write an XML/JSON database and show a dialog like “An operation is pending or you have not close the previously launched application. Please wait and/or close the launched app before continuing.”

Alternatively, is there any other solution to solve this problem with the current Python API? Thanks a lot for your time Big Grin