Skip to Main Content
Programming Python, Second Edition
book

Programming Python, Second Edition

by Mark Lutz
March 2001
Intermediate to advanced content levelIntermediate to advanced
1296 pages
38h 8m
English
O'Reilly Media, Inc.
Content preview from Programming Python, Second Edition

Interprocess Communication

As we saw earlier, when scripts spawn threads -- tasks that run in parallel within the program -- they can naturally communicate by changing and inspecting shared global memory. As we also saw, some care must be taken to use locks to synchronize access to shared objects that can’t be updated concurrently, but it’s a fairly straightforward communication model.

Things aren’t quite as simple when scripts start processes and programs. If we limit the kinds of communications that can happen between programs, there are many options available, most of which we’ve already seen in this and the prior chapters. For example, the following can all be interpreted as cross-program communication devices:

  • Command-line arguments

  • Standard stream redirections

  • Pipes generated by os.popen calls

  • Program exit status codes

  • Shell environment variables

  • Even simple files

For instance, sending command-line options and writing to input streams lets us pass in program execution parameters; reading program output streams and exit codes gives us a way to grab a result. Because shell variable settings are inherited by spawned programs, they provide another way to pass context in. Pipes made by os.popen and simple files allow even more dynamic communication -- data can be sent between programs at arbitrary times, not only at program start and exit.

Beyond this set, there are other tools in the Python library for doing IPC -- Inter-Process Communication. Some vary in portability, and all vary ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Python, 3rd Edition

Programming Python, 3rd Edition

Mark Lutz

Publisher Resources

ISBN: 0596000855Supplemental ContentCatalog PageErrata