Skip to Content
Python in a Nutshell, 3rd Edition
book

Python in a Nutshell, 3rd Edition

by Alex Martelli, Anna Ravenscroft, Steve Holden
April 2017
Intermediate to advanced content levelIntermediate to advanced
769 pages
21h 56m
English
O'Reilly Media, Inc.
Content preview from Python in a Nutshell, 3rd Edition

Chapter 14. Threads and Processes

A thread is a flow of control that shares global state (memory) with other threads; all threads appear to execute simultaneously, although they are usually “taking turns” on a single processor/core. Threads are not easy to master, and multithreaded programs are often hard to test, and to debug; however, as covered in “Use Threading, Multiprocessing, or async Programming?”, when used appropriately, multithreading may sometimes improve program performance in comparison to traditional “single-threaded” programming. This chapter covers the facilities that Python provides for dealing with threads, including the threading, queue, and concurrent modules.

A process is an instance of a running program. The operating system protects processes from one another. Processes that want to communicate must explicitly arrange to do so via inter-process communication (IPC) mechanisms. Processes may communicate via files (covered in Chapter 10) and databases (covered in Chapter 11). The general way in which processes communicate using data storage mechanisms, such as files and databases, is that one process writes data, and another process later reads that data back. This chapter covers the Python standard library modules subprocess and multiprocessing; the process-related parts of the module os, including simple IPC by means of pipes; and a cross-platform IPC mechanism known as memory-mapped files, which is supplied to Python programs by the module mmap.

Network ...

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

Python in a Nutshell, 4th Edition

Python in a Nutshell, 4th Edition

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire

Publisher Resources

ISBN: 9781491913833Errata Page