import threading class AsyncTask(threading.Thread): """ AsyncTask AsyncTask is a utility class allowing to execute a task asynchronously in a thread. For more informations read the constructor documentation. @author Jérémi Nihart / EndMove @link https://git.endmove.eu/EndMove/WebPicDownloader @version 1.0.0 @since 2022-09-01 """ # Variables __stop = None __callback = None __args: list = None # Constructor def __init__(self, callback, args=()) -> None: """ Constructor => Spacify here the function that should be launched asynchronously. Then use the function {AsyncTask.start()} to start the thread and the processing. [!]: The function {AsyncTask.run()} is reserved for the thread and should not be run from outside. :callback: -> Is the function to launch asynchronously. :args: -> Argument to pass to the function when executing it. """ super().__init__() self.__stop = threading.Event() self.__callback = callback self.__args = args def run(self) -> None: """ [!] : This function should not be used! Start the task with {AsyncTask.start()}! """ self.__callback(*self.__args) def stop(self) -> None: # TODO self.__stop.set()