πŸ“•KThread

The KThread class is a main component of the KThreading library.

The KThread class is a main component of the KThreading library and serves a similar purpose as the threading.Thread class. However, it provides additional functions that offer greater control over threads. These additional functions allow for more fine-grained management and manipulation of threads during runtime.

class KThread(
    target: typing.Callable,          # function or lambda
    name: str = None,                 # a thread name
    daemon: bool = False,             # daemonize thread
    on_error: typing.Callable = None  # error handler
)
  • target (required typing.Callable) – The target parameter in the KThread class is used to specify the function that will be executed in the thread. It accepts a function as its argument, which will be invoked when the thread starts running.

  • name (optional str; default=None) – The name parameter in the KThread class is used to assign a name or identifier to the thread.

  • daemon (optional bool; default=True) – The daemon parameter in the KThread class is used to specify whether the thread should be marked as a daemon thread or not. A daemon thread is a background thread that runs independently of the main program. If the daemon parameter is set to True, the thread will automatically terminate when the main threads stops, regardless of its execution status. However, if the daemon parameter is set to False, the thread will continue to run even after the main thread has completed its execution. Set it to True for better thread kill result.

  • on_error (optional typing.Callable; default=None) – The on_error parameter in the KThread class is used to specify a function as an error handler for unhandled exceptions thrown in the thread. This function will be called when an unhandled exception occurs in the thread. This allows you to configure error handling and gracefully terminate the thread in case of errors. If this parameter is not specified, the exception will be thrown on the unhandled thread.

Last updated