O'Reilly logo

Python Parallel Programming Cookbook by Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to run a process in the background

Running a process in background is a typical mode of execution of laborious processes that do not require your presence or intervention, and this course may be concurrent to the execution of other programs. The Python multiprocessing module allows us, through the daemonic option, to run background processes.

How to do it...

To run a background process, simply follow the given code:

import multiprocessing import time def foo(): name = multiprocessing.current_process().name print ("Starting %s \n" %name) time.sleep(3) print ("Exiting %s \n" %name) if __name__ == '__main__': background_process = multiprocessing.Process\ (name='background_process',\ target=foo) background_process.daemon = True NO_background_process ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required