threading module is built on top of module
thread and supplies multithreading functionality in a more usable, higher-level form. The general approach of
threading is similar to that of Java, but locks and conditions are modeled as separate objects (in Java, such functionality is part of every object), and threads cannot be directly controlled from the outside (which means there are no priorities, groups, destruction, or stopping). All methods of objects supplied by
threading are atomic.
threading provides numerous classes for dealing with threads, including
Semaphore. Besides factory functions for the classes detailed in the following sections,
threading supplies the
currentThread factory function.
t models a thread. You can pass
t’s main function as an argument when you create
t, or you can subclass
Thread and override the
run method (you may also override
_ _init_ _ but should not override other methods).
t is not ready to run when you create it; to make
t ready (active), call
.start( ). Once
t is active, it terminates when its main function ends, either normally or by propagating an exception. A
t can be a daemon, meaning that Python can terminate even if