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

Python- Basic Concepts part 1
1. What is Python? Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence. It is...

Benefits of Design Patterns in Application Development
Application developments is a tedious job. Programmers write code and test it again and again to make sure their software works fine. So designing complex software is a hard nut to crack. Skilled programmers...

A program to determine the molecular weight of a hydrocarbon based on the number of Hydrogen,Carbon and Oxygen atoms.
import osimport math# A program to calculate Molecular Weight of a Hydrocarbon # These are the atomic weights(grams/mole) of Hydrogen,Carbon and OxygenatomicwtH = 1.0079atomicwtC = 12.011atomicwtO = 15.994Hatoms...

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

Python Script for random Password generation
from random import randintdef passwordgen(request): str_not_include = "1 L I i l o O 0" str_small ="abcdefghjkmnpqrstuvwxyz" str_caps = str_small.upper() str_num = "23456789" str_special...
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