February 2019
Intermediate to advanced
672 pages
16h 50m
English
To illustrate the concept of running multiple processes on one operating system, let's look at a quick example in Python. Let's take a look at the Chapter13/example1.py file, as shown in the following code:
# Chapter13/example1.pyfrom multiprocessing import Processimport timedef count_down(name, delay): print('Process %s starting...' % name) counter = 5 while counter: time.sleep(delay) print('Process %s counting down: %i...' % (name, counter)) counter -= 1 print('Process %s exiting...' % name)if __name__ == '__main__': process1 = Process(target=count_down, args=('A', 0.5)) process2 = Process(target=count_down, args=('B', 0.5)) process1.start() process2.start() process1.join() process2.join() print('Done.')