threading — Thread-based parallelism — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Concurrent Execution

multiprocessing — Process-based parallelism

Python Module Index

3.16.0a0 Documentation

The Python Standard Library

_thread: Low-level threading API.

This module constructs higher-level threading interfaces on top of the lower level _thread module.

WebAssembly platforms

This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information.

concurrent.futures.ThreadPoolExecutor

concurrent.futures.ThreadPoolExecutor offers a higher level interface to push tasks to a background thread without blocking execution of the calling thread, while still being able to retrieve their results when needed.

queue: A synchronized queue class.

concurrent.futures.ThreadPoolExecutor offers a higher level interface to push tasks to a background thread without blocking execution of the calling thread, while still being able to retrieve their results when needed.

asyncio: Asynchronous I/O.

concurrent.futures.ThreadPoolExecutor offers a higher level interface to push tasks to a background thread without blocking execution of the calling thread, while still being able to retrieve their results when needed.

Global Interpreter Lock

Thread-local data¶

Thread-local data is data whose values are thread specific. If you have data that you want to be local to a thread, create a local object and use its attributes:

contextvars.Context

This constructor should always be called with keyword arguments. Arguments are:

sys.flags.thread_inherit_context

This constructor should always be called with keyword arguments. Arguments are:

PythonFinalizationError

Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception – or until the optional timeout occurs.

Using locks, conditions, and semaphores in the with statement¶

All of the objects provided by this module that have acquire and release methods can be used as context managers for a with statement. The acquire method will be called when the block is entered, and release will be call