π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
) β Thetarget
parameter in theKThread
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
) β Thename
parameter in theKThread
class is used to assign a name or identifier to the thread.daemon (optional
bool
;default=True
) β Thedaemon
parameter in theKThread
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 thedaemon
parameter is set toTrue
, the thread will automatically terminate when the main threads stops, regardless of its execution status. However, if thedaemon
parameter is set toFalse
, the thread will continue to run even after the main thread has completed its execution. Set it toTrue
for better thread kill result.on_error (optional
typing.Callable
;default=None
) β Theon_error
parameter in theKThread
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