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.coroutine def countdown(number, n): while n > 0: print('T-minus', n, '({})'.format(number)) yield from asyncio.sleep(1) n -= 1 loop = 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.5 import time def 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 execution result=pool.map(squareNumber, [2,4,6]) pool.close() pool.join()
0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

Simulation of a die-roll:Usage of random module
Task:Simulation of a simple die-rolling game,where we keep rolling a six-sided die until we have rolled a total of 20. To simulate a six-sided die roll, we need a way to generate a random integer between...

Debugging Python code
If you are getting an error while executing your python code, the better way of running your python code is by using -i switch. ex: python -i scriptname.py once you run the above command, your execution...

map function in python
The function map takes a function and an iterable as arguments and returns a new iterable with the function applied to each argument. Example: def add_five(x): return x+5 nums = result = list(map(add_five,...

Python Important Operation Formats and Sytnax.
Hello Python Enthusiast, Though Python is considered as one of the easisest language to learn in the market, many freshers and beginners will find great difficulty in understansing the syntax and also...

Python- Basic Concepts part 2
1. Other Numerical Operations a. Exponentiation Besides addition, subtraction, multiplication, and division, Python also supports exponentiation, which is the raising of one number to the power of...
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