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

Identity operators
Identity operators Operation Syntax Function Identity a is b is_(a, b) Membership operators Operation Syntax Function Containment obj in seq contains(seq, obj)

Why Python
Python can be used in any futuristics technology A= Analytics Data Science Artificial Intelligence(AI) Neural Network(NN) Natural Language Processing(NLP) Computer Vision(OpenCV) In Analytics...

Using the Math Library in Python
Using the Math Library in Python. Python provides many useful mathematical functions in a special math library. A library is a module that contains some useful definitions. We now consider...

How to know if an object is iterable?
An object in python is said to be an iterable if it obeys one of the following two rules:- 1. Object must consist of __getitem__ method 2. Object must consist of __iter__ method. String objects generally...

C, Cpp, Java, Python, Javascript Programming Languages
Learning C is as good as Learning a Natural Language(such as English, Hindi, Telugu, Tamil etc) We use Natural Languages to communicate with humans whereas we use Programming Languages such as C, Cpp,...
V

Vamshi

0 0
0
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