SteamDeckHomebrew / decky-loader

A plugin loader for the Steam Deck.
https://decky.xyz
GNU General Public License v2.0
4.26k stars 154 forks source link

Call plugin unload function after stopping event loop #539

Closed Jan200101 closed 6 months ago

Jan200101 commented 9 months ago

This can prevent race conditions where unload is clearing data but main is still working with it

Please tick as appropriate:

If you're wanting to update a translation or add a new one, please use the weblate page: https://weblate.werwolv.net/projects/decky/

Description

During the unload long-running code is still active causing possible race conditions when unloads cleans up data which main was referencing.

Example Plugin

class Plugin:
    data = []

    async def _main(self):
        while True:
            self.data.append(len(self.data))
            decky_plugin.logger.info(self.data)
            await asyncio.sleep(0.1)

    async def _unload(self):
        self.data = None
TrainDoctor commented 6 months ago

Going to give this a go. Apologies it took so long to get to this. (Edit: Had to manually rebase PR locally for testing purposes.)