Skip to content

Thread unloading #218

@KirillMysnik

Description

@KirillMysnik

Currently any threads started by the plugin are left running when the plugin unloads.

While it's generally incorrect to kill the threads from outside, maybe we should at least warn about such threads?

E.g.

from threading import Thread
from warnings import warn

from core import WeakAutoUnload


class GameThread(WeakAutoUnload, Thread):
    def _add_instance(self, caller):
        super()._add_instance(caller)
        self._caller = caller

    def _unload_instance(self):
        if self.is_alive():
            warn(
                f"Thread '{self.name}' ({self.ident}) from '{self._caller}' "
                f"is running even though its plugin has been unloaded!")

This will report all threads running at the time of plugin unloading even if the plugin implements some mechanism to stop its threads.

To give a thread some time to realize that the plugin is unloaded, that check can be wrapped and delayed with Delay.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions