17.4. thread Module

Let's take a look at what the thread module has to offer. In addition to being able to spawn threads, the threadmodule also provides a basic synchronization data structure called a lock object (a.k.a. primitive lock, simple lock, mutual exclusion lock, mutex, binary semaphore). As we mentioned earlier, such synchronization primitives go hand-in-hand with thread management.

Listed in Table 17.1 are a list of the more commonly-used thread functions and LockType lock object methods:

Table 17.1. thread Module and Lock Objects
Function/MethodDescription
thread Module Functions
start_new_thread(function, args, kwargs=None)spawns a new thread and execute function with the given args and optional kwargs
allocate_lock()allocates LockType ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.