Python Threading

  • It is a light-weight process and they don’t require more memory overhead they are less expensive than processes.
  • A thread has a starting, an execution sequence, and a conclusion. It has an instruction pointer that monitors where inside its context it is currently running.
    • It can be pre-interrupted.
    • It can temporarily be put on hold (also called sleeping) while other threads are running – this is known as yielding.
  • The newer threading module included with Python 2.4 provides much more powerful, high-level support for threads than the thread module.
  • A Python threading module exposes all the methods of the thread module and it will give several extra methods.
    • threading.activeCount() – It returns the number of thread objects that are active.
    • threading.currentThread() − It returns the number of thread objects in the caller’s thread control.
    • threading.enumerate() − It returns a list of all thread objects that are currently active.
  • Additionally the methods, and thread module has thread class that implements threading. These methods provided by the Thread class are given below:
    • run() − This method is the entry point for a thread.
    • start() − This method starts a thread by calling the run method.
    • join([time]) − This waits for threads to terminate.
    • isAlive() − This method checks whether a thread is still executing.
    • getName() − This method returns the name of a thread.
    • setName() − This method sets the name of a thread.
Python thread

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,