IKH

Introduction

  • Python supports multitasking (executing several tasks simultaneously) through various methods:
    • Process based multi tasking.
    • Thread based multi tasking.

Process Based Multi Tasking

  • Executing several tasks simultaneous where each task is a separate independent process is called process based multi tasking.
  • We can listen music and browse the internet at the same time. The processes in this example are the music player and browser.

Thread Based Multi Tasking

  • Executing several tasks simultaneously where each task is a separate independent part of the same program, is called thread based multi tasking, and each independent part is called a thread. This type of multi tasking is best suitable at programmatic level.
  • A text editor can format text at the same time it is printing, as long as these two actions are performed by two separate threads.

Note

  • Whether it is process based or thread based, the main advantage of multi tasking is to improve performance of the system by reducing response time.
  • The main important application areas of multi threading are:
    • To implement multimedia graphics.
    • To develop animations.
    • To develop video games.
    • To develop web and application servers etc.
  • Where ever a group of independent jobs are available, then it is highly recommended to execute simultaneously instead of executing one by one. For such type of cases we should go for multi threading.
  • Python provides one inbuilt module “threading” to provide support for developing threads. Hence developing multi threaded programs is very easy in python. Every python program by default contains one thread which is nothing but main thread.

Question

Program to print name of current executing thread?

Python
import threading 
print("Current Executing Thread:",threading.current_thread().name)

Output

PowerShell
Current Executing Thread: MainThread

Note

  • Threading module contains function current_thread() which returns the current executing thread object. On this object if we call ‘name’ variable then we will get current executing thread name.

Ungraded Questions

Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!


Name
Email
Phone

Report an error