UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Python Concurrent v/s Parallel Programming

Logeswaran
11/01/2018 0 0
Concurrent means, more than one task happening at a time in interleaved fashion, (ie.,)Task 'A' starts, and Task 'B' starts before task 'A' finish, after processing its(A and B) own purpose both the task will finish, you can assume, only one statement will execute in any time.
 
Here we should not confuse concurrent with parallel:
 
Parallel, is running more than one task in different process at a time, you can assume, it will execute as many statements as much thread you have assigned/created.
 
Concurrent vs Parallel Execution:
 
#Concurrent(Allows to deal with I/O while computing)print('------- Concurrent Programming in Python --------')import asyncio
#This library will work only from python3.5@asyncio.coroutinedef countdown(number, n): while n > 0: print('T-minus', n, '({})'.format(number)) yield from asyncio.sleep(1) n -= 1loop = asyncio.get_event_loop()tasks = [ asyncio.ensure_future(countdown("A", 5)), asyncio.ensure_future(countdown("B", 5)), asyncio.ensure_future(countdown("c", 5))]loop.run_until_complete(asyncio.wait(tasks))loop.close()
#Parallel(helps to increase the throughput of the machine)print('------- Parallel Programming in Python --------')from multiprocessing.dummy import Pool as ThreadPool
#Above library will work only from python3.5import timedef squareNumber(nn): time.sleep(5) for i in range(nn): print (i)pool = ThreadPool(2) #by increasing the thread count(2),it will create a new thread to handle parallel executionresult=pool.map(squareNumber, [2,4,6])pool.close()pool.join()
0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

Arithmetic operators
Operation Syntax Function Addition a + b add(a, b) Subtraction a - b sub(a, b) Multiplication a * b mul(a, b) Division a / b truediv(a, b) Concatenation seq1...

Python Introduction
Python is an object-oriented programming language created by Rossum in 1989. It is ideally designed for rapid prototyping of complex applications. It has interfaces to many OS system calls and libraries...
I

Imran

0 0
0

A Python Program to calculate Variance and Standard Deviation
Finding the variance and the standard deviation. Variance and Standard Deviation are related measures of dispersion that tell us more about a list of numbers,like are they...

Two lists using Loops - Python Program 1
To generate a list of all possible combinations of two lists using loops, you can use nested loops to iterate through both lists and create a new list that contains all the combinations. list1 = list2...

Top Programming Languages 2017: Every Beginner Should Learn
Every year a plethora of job opportunities are being created for skilled programmers. So if you are thinking of honing your coding skills it is really a bright idea. But with so many programming languages...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more