Main menu

Pages

Multiprocessing in python tutorial 2022

Multiprocessing in python tutorial 2022, When you use your mobile phone or your computer, you can run several programs at the same time, as each active program in memory is considered a (Process), and the process of running several programs with each other at the same time is called (Multiprocessing).


Multiprocessing in python tutorial 2022


The concept of multitasking in the programming language Python Multiprocessing


The multi-tasking mechanism is used in the Python programming language to make the program capable of executing several commands with each other as if they are being executed simultaneously, and this feature refers to the system's ability to support more than one processor at the same time, where applications are divided into a multiprocessor system into smaller procedures that operate independently.


Thread concept in Python programming language


(Thread) is a set of commands that are executed while executing other commands in the same program, and the user can run more than one (Thread) at the same time and it is also possible to share information among them.


The importance of multitasking in the Python programming language


This mechanism in the field of programming languages has many advantages, as one program can execute many commands at the same time. The importance of this term lies in:


  • Make the user able to perform many operations some at the same time.
  • Making application's designs appear more beautiful and enabling the user to add effects to it.
  • Each program that the user runs works in isolation from the rest of the commands in the other programs, and therefore, in the event of any (Error) occurring in the (Thread), it will not affect the rest of the commands in the program.


The most important functions of the threading module in the Python programming language


The most important functions of the threading module in the Python programming language


threading.active_count()


This function returns the number of threads being executed at the moment.


threading.main_thread()


This function returns the main object of the program.


threading.current_thread()


This function returns the thread being executed at the moment.


threading.enumerate()


This function returns a list object which contains every thread of type being executed at the moment.


The most important functions of the Thread class in the Python programming language


start()


This function is used to run an object of type (Thread) that is called it.


is_alive()



This function returns True if the thread has not finished, and returns False if it has finished.


name


Returns the name given to the thread object that called it.