Copyright by Jeremy M. Jones, Noah Gift

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 10. Processes and Concurrency

Introduction

Dealing with processes as a Unix/Linux systems administrator is a fact of life. You need to know about startup scripts, run levels, daemons, cron jobs, long-running processes, concurrency, and a host of other issues. Fortunately, Python makes dealing with processes quite easy. Since Python 2.4, Subprocess has been the one-stop shop module that allows you to spawn new processes and talk to standard input, standard output, and standard error. While talking to a processes is one aspect of dealing with processes, it is also import to understand how to deploy and manage long-running processes as well.

Subprocess

With Python 2.4 came subprocess, which takes the place of several older modules: os.system, os.spawn, os.popen, and popen2 commands. Subprocess is a revolutionary change for systems administrators and developers who need to deal with processes and “shelling out.” It is now a one-stop shop for many things dealing with processes and it may eventually include the ability to manage a flock of processes.

Subprocess might just be the single most important module for a systems administrator, as it is the unified API to “shelling out.” Subprocess is responsible for the following things in Python: spawning new processes connecting to standard input, connecting to standard output, connecting to error streams, and listening to return codes.

To whet your appetite, let’s use the KISS principle (Keep It Simple Stupid), and do the absolute simplest ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required