Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
Typing Speed
Week

Target

Achieved

1

25

23

2

30

26

3

30

28

4

35

31
Jobs Applied
#

Company

1

aerosoft corp

2

aufait technologies

3

Admin-Ahead Server
Technologies

Designation

Curren...
Multiprocessing in python
shafeeque
●

shafeequemonp@gmail.com

●

www.facebook.com/shafeequemonppambodan

●

twitter.com/...
Introduction
What is a process?
●

●

●

●

A process is an instance of a computer program that is being
executed.
It cont...
Multiprocessing
●

●

Multiprocessing is the use of two or more central processing units(CPUs)
within a single computer sy...
Python Multiprocessing:
●

●

●

●

As CPU manufacturers start adding more and more cores to their
processors, creating pa...
Processes, Queues and
Locks:
● The multiprocessing module comes with plenty of built-in options for building 
a parallel a...
●

If you want to pass arguments to the function, simply provide a args keyword 
argument like so:
from multiprocessing im...
Queues
●

●

Queue objects are exactly what they sound like: a thread/process 
safe,FIFO data structure 
Usage:
from multi...
Locks
●

●

Like Queue objects, Locks are relatively straightforward.
They allow your code to claim the lock, blocking oth...
If this presentation helped you, please visit our page facebook.com/baabtra and
like it.

Thanks in advance.
www.baabtra.c...
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Start up Vil...
Multiprocessing in python
Upcoming SlideShare
Loading in …5
×

Multiprocessing in python

1,291 views

Published on

Multiprocessing in python

Published in: Education, Technology
  • Be the first to comment

Multiprocessing in python

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Typing Speed Week Target Achieved 1 25 23 2 30 26 3 30 28 4 35 31
  3. 3. Jobs Applied # Company 1 aerosoft corp 2 aufait technologies 3 Admin-Ahead Server Technologies Designation Current Status 03/09/13 Php developer Applied Date waiting 03/09/13 waiting 03/09/13 waiting
  4. 4. Multiprocessing in python shafeeque ● shafeequemonp@gmail.com ● www.facebook.com/shafeequemonppambodan ● twitter.com/shafeequemonp ● in.linkedin.com/in/shafeequemonp ● 9809611325
  5. 5. Introduction What is a process? ● ● ● ● A process is an instance of a computer program that is being executed. It contains the program code and its current activity process Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently In fact only one process can be executing at any one time on a single-core CPU (unless using multithreading or other similar technology).
  6. 6. Multiprocessing ● ● Multiprocessing is the use of two or more central processing units(CPUs) within a single computer system The term also refers to the ability of a system to support more than one processor and/or the ability to allocate tasks between them.
  7. 7. Python Multiprocessing: ● ● ● ● As CPU manufacturers start adding more and more cores to their processors, creating parallel code is a great way to improve performance. There are a lot of options out there for parallel development (such as functional languages or developer toolkits). Along with the release of Python 2.6 came a new module called multiprocessing The multiprocessing module lets you write parallelized code using processes in relatively simple code
  8. 8. Processes, Queues and Locks: ● The multiprocessing module comes with plenty of built-in options for building  a parallel application ● Three most basic (and safest) are the Process, Queue and Lock classes Processes: ● The Process is an abstraction that sets up another (Python) process, provides it  code to run and a way for the parent application to control execution from multiprocessing import Process#import the Process class def say_hello(name='world'):#create a function the process will run print "Hello, %s" % name p = Process(target=say_hello)#instantiate a Process object with the function it should run p.start()#The process will run and return it's result p.join()#process to complete via p.join()
  9. 9. ● If you want to pass arguments to the function, simply provide a args keyword  argument like so: from multiprocessing import Process def say_hello(name='world'): print "Hello, %s" % name p = Process(target=say_hello, args=('Daniel',)) p.start() p.join()
  10. 10. Queues ● ● Queue objects are exactly what they sound like: a thread/process  safe,FIFO data structure  Usage: from multiprocessing import Queue q = Queue() q.put('Why hello there!') q.put(['a', 1, {'b': 'c'}]) q.get() # Returns 'Why hello there!' q.get() # Returns ['a', 1, {'b': 'c'}] ● Queues are especially useful when passed as a parameter to a Process' target  function to enable the Process to consume (or return) data.
  11. 11. Locks ● ● Like Queue objects, Locks are relatively straightforward. They allow your code to claim the lock, blocking other processes from  executing similar code until the process has completed and release the lock usage: from multiprocessing import Lock l = Lock() l.acquire() print 'Ha! Only I can write to stdout!' l.release()
  12. 12. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  13. 13. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550

×