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

10 Best Python IDEs
Python is a very popular programming language. It's open source and used today as scripting language, web development, mobile and desktop in many areas thanks to the endless modules options it has While...

Python breaks into the top three programming languages in the Tiobe Index for the first time.
Python breaks into the top three programming languages in the Tiobe Index for the first time. The popularity of Python shows no sign of waning, with the programming language entering the top three in...


The Zen of Python
Writing programs that actually do what they are supposed to do is just one component of being a good python programmer. It's also important to write clean code that is easily understood, even weeks after...

Build an interactive Dictionary using Python 3.x
I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through...
B

Biswanath Banerjee

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