

{"id":26633,"date":"2018-08-30T05:23:09","date_gmt":"2018-08-29T23:53:09","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=26633"},"modified":"2026-04-24T16:51:06","modified_gmt":"2026-04-24T11:21:06","slug":"python-multiprocessing","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/","title":{"rendered":"Python Multiprocessing Module With Example"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Today, in this Python tutorial, we will see Python Multiprocessing. Moreover, we will look at the package and structure of Multiprocessing in Python. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we will discuss the process class in Python Multiprocessing, and also get information about the process. <\/span><\/p>\n<p><span style=\"font-weight: 400\">To make this happen, we will borrow several methods from the <\/span>multithreading<span style=\"font-weight: 400\"> module. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Along with this, we will learn the lock and pool classes in Python Multiprocessing.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, let\u2019s begin the Multiprocessing in Python tutorial.<\/span><\/p>\n<div id=\"attachment_26652\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26652\" class=\"wp-image-26652 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg\" alt=\"Python Multiprocessing Module With Example\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-26652\" class=\"wp-caption-text\">Python Multiprocessing Module With Example<\/p><\/div>\n<h3>What is Python Multiprocessing?<\/h3>\n<p><span style=\"font-weight: 400\">First, let\u2019s talk about parallel processing. This is a way to simultaneously break up and run program tasks on multiple microprocessors. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In effect, this is an effort to reduce processing time and is something we can achieve with a computer with two or more processors or using a computer network. We also call this parallel computing.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Okay, now coming to Python Multiprocessing, this is a way to improve performance by creating parallel code. <\/span><\/p>\n<p><span style=\"font-weight: 400\">CPU manufacturers make this possible by adding more cores to their processors. In a multiprocessing system, applications break into smaller routines to run independently. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Take a look at a single-processor system. Given several processes at once, it struggles to interrupt and switch between tasks. <\/span><\/p>\n<p><strong>Where can Multiprocessing be used in Python?<\/strong><\/p>\n<ul>\n<li><strong>Heavy lifting( CPU Bound):<\/strong> If you have a huge task like video editing and more, where the whole power of the computer is used to finish the work.<\/li>\n<li><strong>Safety:<\/strong> Each process has to be in its own line. Even if one crashes, the program still keeps running.<\/li>\n<li><strong>Speed:<\/strong> It lets you use all the power of the CPU, making the program run faster by setting a limit to performing the task one by one.<\/li>\n<\/ul>\n<h3>Python Multiprocessing Package<\/h3>\n<p><i><span style=\"font-weight: 400\">Multiprocessing in<\/span><\/i> <span style=\"font-weight: 400\">Python<\/span><span style=\"font-weight: 400\">\u00a0is a package we can use with Python to spawn processes using an API that is much like the <\/span><i><span style=\"font-weight: 400\">threading<\/span><\/i><span style=\"font-weight: 400\"> module. <\/span><\/p>\n<p><span style=\"font-weight: 400\">With support for both local and remote concurrency, it lets the programmer make efficient use of multiple processors on a given machine. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Before we can begin explaining it to you, let\u2019s take an example of Pool- an object, a way to parallelize executing a function across input values and distributing input data across processes. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This is data parallelism (Make a module out of this and run it)-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">from multiprocessing import Pool\r\ndef f(x):\r\n    return x*x\r\nwith Pool(5) as p:\r\n    print(p.map(f,[1,2,3]))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[1, 4, 9]<\/div>\n<p><span style=\"font-weight: 400\">Want to find out how many cores your machine has? Try the cpu_count() method.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import multiprocessing\r\n&gt;&gt;&gt; multiprocessing.cpu_count()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">4<\/div>\n<h3>Structure of a Python Multiprocessing System<\/h3>\n<p><span style=\"font-weight: 400\">So what is such a system made of? We have the following possibilities:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>A multiprocessor-<\/strong> a computer with more than one central processor.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>A multi-core processor-<\/strong> a single computing component with more than one independent actual processing unit\/ cores.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">In either case, the CPU is able to execute multiple tasks at once, assigning a processor to each task.<\/span><\/p>\n<h3>Python Multiprocessing Process Class<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s talk about the <\/span><i><span style=\"font-weight: 400\">Process<\/span><\/i><span style=\"font-weight: 400\"> class in Python Multiprocessing first. This is an abstraction to set up another process and let the parent application control execution. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Here, we observe the start() and join() methods. Let\u2019s first take an example.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import multiprocessing\r\nfrom multiprocessing import Process\r\ndef testing():\r\n      print(\"Works\")\r\ndef square(n):\r\n       print(\"The number squares to \",n**2)\r\ndef cube(n):\r\n       print(\"The number cubes to \",n**3)\r\nif __name__==\"__main__\":\r\n   p1=Process(target=square,args=(7,))\r\n   p2=Process(target=cube,args=(7,))\r\n   p3=Process(target=testing)\r\n   p1.start()\r\n   p2.start()\r\n   p3.start()\r\n   p1.join()\r\n   p2.join()\r\n   p3.join()\r\n   print(\"We're done\")<\/pre>\n<p><span style=\"font-weight: 400\">We saved this as pro.py on our desktop and then ran it twice from the command line. This is the output we got:<\/span><\/p>\n<div id=\"attachment_26762\" style=\"width: 223px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26762\" class=\"wp-image-26762 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process1.png\" alt=\"Python Multiprocessing\" width=\"213\" height=\"51\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process1.png 213w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process1-150x36.png 150w\" sizes=\"auto, (max-width: 213px) 100vw, 213px\" \/><\/a><p id=\"caption-attachment-26762\" class=\"wp-caption-text\">Process class in Python Multiprocessing<\/p><\/div>\n<div id=\"attachment_26763\" style=\"width: 215px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26763\" class=\"wp-image-26763 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process2.png\" alt=\"Python Multiprocessing\" width=\"205\" height=\"51\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process2.png 205w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/process2-150x37.png 150w\" sizes=\"auto, (max-width: 205px) 100vw, 205px\" \/><\/a><p id=\"caption-attachment-26763\" class=\"wp-caption-text\">Python Multiprocessing &#8211; Process class<\/p><\/div>\n<p><span style=\"font-weight: 400\">Let\u2019s understand this piece of code. Process() lets us instantiate the Process class. start() tells Python to begin processing. <\/span><\/p>\n<p><span style=\"font-weight: 400\">But then if we let it be, it consumes resources and we may run out of those at a later point in time. This is because it lets the process stay idle and not terminate. <\/span><\/p>\n<p><span style=\"font-weight: 400\">To avoid this, we make a call to join(). With this, we don\u2019t have to kill them manually. Join stops execution of the current program until a process completes. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This makes sure the program waits for p1 to complete and then for p2 to complete. Then, it executes the next statements of the program. <\/span><\/p>\n<p><span style=\"font-weight: 400\">One last thing, the <\/span><i><span style=\"font-weight: 400\">args<\/span><\/i><span style=\"font-weight: 400\"> keyword argument lets us specify the values of the argument to pass. Also, <\/span><i><span style=\"font-weight: 400\">Target<\/span><\/i><span style=\"font-weight: 400\"> lets us select the function for the process to execute.<\/span><\/p>\n<h3>Getting Information about Processes in Python<\/h3>\n<h4>1. Getting Process ID and checking if alive<\/h4>\n<p><span style=\"font-weight: 400\">We may want to get the ID of a process or that of one of its children. We may also want to find out if it is still alive. The following program demonstrates this functionality:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import multiprocessing\r\nfrom multiprocessing import Process\r\nimport os\r\ndef child1():\r\n     print(\"Child 1\",os.getpid())\r\ndef child2():\r\n        print(\"Child 2\",os.getpid())\r\nif __name__==\"__main__\":\r\n   print(\"Parent ID\",os.getpid())\r\n   p1=Process(target=child1)\r\n   p2=Process(target=child2)\r\n   p1.start()\r\n   p2.start()\r\n   p1.join()\r\n   alive='Yes' if p1.is_alive() else 'No'\r\n   print(\"Is p1 alive?\",alive)\r\n   alive='Yes' if p2.is_alive() else 'No'\r\n   print(\"Is p2 alive?\",alive)\r\n   p2.join()\r\n   print(\"We're done\")<\/pre>\n<div id=\"attachment_26764\" style=\"width: 153px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/pid1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26764\" class=\"wp-image-26764 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/pid1.png\" alt=\"Python Multiprocessing\" width=\"143\" height=\"75\" \/><\/a><p id=\"caption-attachment-26764\" class=\"wp-caption-text\">Getting Information<\/p><\/div>\n<div id=\"attachment_26765\" style=\"width: 144px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/pid2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26765\" class=\"wp-image-26765 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/pid2.png\" alt=\"Python Multiprocessing\" width=\"134\" height=\"75\" \/><\/a><p id=\"caption-attachment-26765\" class=\"wp-caption-text\">Getting Information<\/p><\/div>\n<p><span style=\"font-weight: 400\">In Python multiprocessing, each process occupies its own memory space to run independently. It terminates when the target function is done executing.<\/span><\/p>\n<h4>2. Getting Process Name<\/h4>\n<p><span style=\"font-weight: 400\">We can also set names for processes so we can retrieve them when we want. This is to make it more human-readable.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import multiprocessing\r\nfrom multiprocessing import Process, current_process\r\nimport os\r\ndef child1():\r\n     print(current_process().name)\r\ndef child2():\r\n         print(current_process().name)\r\nif __name__==\"__main__\":\r\n   print(\"Parent ID\",os.getpid())\r\n   p1=Process(target=child1,name='Child 1')\r\n   p2=Process(target=child2,name='Child 2')\r\n   p1.start()\r\n   p2.start()\r\n   p1.join()\r\n   p2.join()\r\n   print(\"We're done\")<\/pre>\n<div id=\"attachment_26766\" style=\"width: 128px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/name.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26766\" class=\"wp-image-26766 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/name.png\" alt=\"Python Multiprocessing\" width=\"118\" height=\"51\" \/><\/a><p id=\"caption-attachment-26766\" class=\"wp-caption-text\">Python Multiprocessing &#8211; Process name<\/p><\/div>\n<p><span style=\"font-weight: 400\">As you can see, the current_process() method gives us the name of the process that calls our function. See what happens when we don\u2019t assign a name to one of the processes:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import multiprocessing\r\nfrom multiprocessing import Process, current_process\r\nimport os\r\ndef child1():\r\n        print(current_process().name)\r\ndef child2():\r\n        print(current_process().name)\r\nif __name__==\"__main__\":\r\n   print(\"Parent ID\",os.getpid())\r\n   p1=Process(target=child1)\r\n   p2=Process(target=child2,name='Child 2')\r\n   p1.start()\r\n   p2.start()\r\n   p1.join()\r\n   p2.join()\r\n   print(\"We're done\")<\/pre>\n<div id=\"attachment_26767\" style=\"width: 126px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/name2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26767\" class=\"wp-image-26767 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/name2.png\" alt=\"Python Multiprocessing\" width=\"116\" height=\"52\" \/><\/a><p id=\"caption-attachment-26767\" class=\"wp-caption-text\">Getting process name<\/p><\/div>\n<p><span style=\"font-weight: 400\">Well, the Python Multiprocessing Module assigns a number to each process as a part of its name when we don\u2019t.<\/span><\/p>\n<h3>Python Multiprocessing Lock<\/h3>\n<p><span style=\"font-weight: 400\">Just like the <\/span><i><span style=\"font-weight: 400\">threading<\/span><\/i><span style=\"font-weight: 400\"> module, <\/span>multiprocessing in<span style=\"font-weight: 400\"> Python supports locks. The process involves importing Lock, acquiring it, doing something, and then releasing it. Let\u2019s take a look.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In the following piece of code, we make a process acquire a lock while it does its job.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">from multiprocessing import Process, Lock\r\nlock=Lock()\r\ndef printer(item):\r\n  lock.acquire()\r\n  try:\r\n      print(item)\r\n  finally:\r\n      lock.release()\r\nif __name__==\"__main__\":\r\n  items=['nacho','salsa',7]\r\n  for item in items:\r\n     p=Process(target=printer,args=(item,))\r\n     p.start()<\/pre>\n<p>Let\u2019s run this code thrice to see what different outputs we get.<\/p>\n<p><span style=\"font-weight: 400\">The lock doesn\u2019t let the threads interfere with each other. The next process waits for the lock to release before it continues.<\/span><\/p>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<br \/>\nsalsa<br \/>\nnachonacho<br \/>\nsalsa<br \/>\n77<br \/>\nnacho<br \/>\nsalsa<\/div>\n<h3>Python Multiprocessing Pool Class<\/h3>\n<p><span style=\"font-weight: 400\">This class represents a pool of worker processes; its methods let us offload tasks to such processes. Let\u2019s take an example (Make a module out of this and run it).<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">from multiprocessing import Pool\r\ndef double(n):\r\n   return n*2\r\nif __name__=='__main__':\r\n   nums=[2,3,6]\r\n   pool=Pool(processes=3)\r\n   print(pool.map(double,nums))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[4, 6, 12]<\/div>\n<p><span style=\"font-weight: 400\">We create an instance of Pool and have it create a 3-worker process. map() maps the function <\/span><i><span style=\"font-weight: 400\">double<\/span><\/i><span style=\"font-weight: 400\"> and an iterable to each process. The result gives us [4,6,12].<\/span><\/p>\n<p><span style=\"font-weight: 400\">Another method that gets us the result of our processes in a pool is the apply_async() method.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">from multiprocessing import Pool\r\ndef double(n):\r\n   return n*2\r\nif __name__=='__main__':\r\n   pool=Pool(processes=3)\r\n   result=pool.apply_async(double,(7,))\r\n   print(result.get(timeout=1))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">14<\/div>\n<p>So, this was all in Python Multiprocessing. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on Multiprocessing Module<\/h3>\n<ol>\n<li>What is the Python multiprocessing module?<\/li>\n<li>How does multiprocessing work in Python?<\/li>\n<li>How to stop multiprocessing in Python?<\/li>\n<li>Explain the purpose of using the multiprocessing module in Python.<\/li>\n<li>Is multiprocessing faster than multithreading in Python?<\/li>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Python Multiprocessing Tutorial, we discussed the complete concept of Multiprocessing in Python. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we looked at Python Multiprocessing pool, lock, and processes. Now, you have an idea of how to utilize your processors to their full potential.\u00a0 <\/span><\/p>\n<p><span style=\"font-weight: 400\">Feel free to explore other blogs on Python, attempting to unleash its power. See you again.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, in this Python tutorial, we will see Python Multiprocessing. Moreover, we will look at the package and structure of Multiprocessing in Python. Also, we will discuss the process class in Python Multiprocessing, and&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":26652,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[8962,8964,10698,10699,10700,10701,10702,10703,10762,10889],"class_list":["post-26633","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-multiprocess-python","tag-multiprocessing-in-python","tag-python-multiprocessing","tag-python-multiprocessing-example","tag-python-multiprocessing-lock","tag-python-multiprocessing-pool","tag-python-multiprocessing-process","tag-python-multithreading","tag-python-pool","tag-python-threading"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Multiprocessing Module With Example - DataFlair<\/title>\n<meta name=\"description\" content=\"Python multiprocessing Module,Python Multithreading,Multiprocessing in Python example,Python Pool,python multiprocessing process,python multiprocessing lock\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Multiprocessing Module With Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python multiprocessing Module,Python Multithreading,Multiprocessing in Python example,Python Pool,python multiprocessing process,python multiprocessing lock\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-29T23:53:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T11:21:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Multiprocessing Module With Example - DataFlair","description":"Python multiprocessing Module,Python Multithreading,Multiprocessing in Python example,Python Pool,python multiprocessing process,python multiprocessing lock","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/","og_locale":"en_US","og_type":"article","og_title":"Python Multiprocessing Module With Example - DataFlair","og_description":"Python multiprocessing Module,Python Multithreading,Multiprocessing in Python example,Python Pool,python multiprocessing process,python multiprocessing lock","og_url":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-08-29T23:53:09+00:00","article_modified_time":"2026-04-24T11:21:06+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Multiprocessing Module With Example","datePublished":"2018-08-29T23:53:09+00:00","dateModified":"2026-04-24T11:21:06+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/"},"wordCount":1179,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg","keywords":["multiprocess python","Multiprocessing in Python","Python Multiprocessing","Python Multiprocessing example","python multiprocessing lock","Python Multiprocessing pool","python multiprocessing process","Python Multithreading","Python Pool","Python Threading"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/","url":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/","name":"Python Multiprocessing Module With Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg","datePublished":"2018-08-29T23:53:09+00:00","dateModified":"2026-04-24T11:21:06+00:00","description":"Python multiprocessing Module,Python Multithreading,Multiprocessing in Python example,Python Pool,python multiprocessing process,python multiprocessing lock","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-multiprocessing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Multiprocessing-Module-01.jpg","width":1200,"height":628,"caption":"Python Multiprocessing Module With Example"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-multiprocessing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Multiprocessing Module With Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=26633"}],"version-history":[{"count":16,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26633\/revisions"}],"predecessor-version":[{"id":147859,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26633\/revisions\/147859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/26652"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=26633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=26633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=26633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}