> **Источник:** https://python-all.ru/3.8/library/concurrency.html
>
> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.

---

# Параллельное выполнение

Модули, описанные в этой главе, обеспечивают поддержку параллельного выполнения кода. Выбор подходящего инструмента зависит от выполняемой задачи (с привязкой к ЦП или к вводу-выводу) и предпочитаемого стиля разработки (событийно-ориентированная кооперативная многозадачность или вытесняющая многозадачность). Ниже приведён обзор:

- [`threading` – параллелизм на основе потоков](https://python-all.ru/3.8/library/threading.html)

  - [Потоковые локальные данные](https://python-all.ru/3.8/library/threading.html#thread-local-data)
  - [Объекты потоков](https://python-all.ru/3.8/library/threading.html#thread-objects)
  - [Объекты блокировок](https://python-all.ru/3.8/library/threading.html#lock-objects)
  - [Объекты RLock](https://python-all.ru/3.8/library/threading.html#rlock-objects)
  - [Объекты условий](https://python-all.ru/3.8/library/threading.html#condition-objects)
  - [Объекты семафоров](https://python-all.ru/3.8/library/threading.html#semaphore-objects)

    - [`Semaphore` Пример](https://python-all.ru/3.8/library/threading.html#semaphore-example)
  - [Объекты событий](https://python-all.ru/3.8/library/threading.html#event-objects)
  - [Объекты таймеров](https://python-all.ru/3.8/library/threading.html#timer-objects)
  - [Объекты барьеров](https://python-all.ru/3.8/library/threading.html#barrier-objects)
  - [Использование блокировок, условий и семафоров в операторе `with`](https://python-all.ru/3.8/library/threading.html#using-locks-conditions-and-semaphores-in-the-with-statement)
- [`multiprocessing` – параллелизм на основе процессов](https://python-all.ru/3.8/library/multiprocessing.html)

  - [Введение](https://python-all.ru/3.8/library/multiprocessing.html#introduction)

    - [Класс `Process`](https://python-all.ru/3.8/library/multiprocessing.html#the-process-class)
    - [Контексты и методы запуска](https://python-all.ru/3.8/library/multiprocessing.html#contexts-and-start-methods)
    - [Обмен объектами между процессами](https://python-all.ru/3.8/library/multiprocessing.html#exchanging-objects-between-processes)
    - [Синхронизация между процессами](https://python-all.ru/3.8/library/multiprocessing.html#synchronization-between-processes)
    - [Совместное использование состояния между процессами](https://python-all.ru/3.8/library/multiprocessing.html#sharing-state-between-processes)
    - [Использование пула рабочих процессов](https://python-all.ru/3.8/library/multiprocessing.html#using-a-pool-of-workers)
  - [Справочник](https://python-all.ru/3.8/library/multiprocessing.html#reference)

    - [`Process` и исключения](https://python-all.ru/3.8/library/multiprocessing.html#process-and-exceptions)
    - [Каналы и очереди](https://python-all.ru/3.8/library/multiprocessing.html#pipes-and-queues)
    - [Разное](https://python-all.ru/3.8/library/multiprocessing.html#miscellaneous)
    - [Объекты соединений](https://python-all.ru/3.8/library/multiprocessing.html#connection-objects)
    - [Примитивы синхронизации](https://python-all.ru/3.8/library/multiprocessing.html#synchronization-primitives)
    - [Разделяемые `ctypes` объекты](https://python-all.ru/3.8/library/multiprocessing.html#shared-ctypes-objects)

      - [Модуль `multiprocessing.sharedctypes`](https://python-all.ru/3.8/library/multiprocessing.html#module-multiprocessing.sharedctypes)
    - [Менеджеры](https://python-all.ru/3.8/library/multiprocessing.html#managers)

      - [Настраиваемые менеджеры](https://python-all.ru/3.8/library/multiprocessing.html#customized-managers)
      - [Использование удалённого менеджера](https://python-all.ru/3.8/library/multiprocessing.html#using-a-remote-manager)
    - [Объекты-прокси](https://python-all.ru/3.8/library/multiprocessing.html#proxy-objects)

      - [Очистка](https://python-all.ru/3.8/library/multiprocessing.html#cleanup)
    - [Пулы процессов](https://python-all.ru/3.8/library/multiprocessing.html#module-multiprocessing.pool)
    - [Слушатели и клиенты](https://python-all.ru/3.8/library/multiprocessing.html#module-multiprocessing.connection)

      - [Форматы адресов](https://python-all.ru/3.8/library/multiprocessing.html#address-formats)
    - [Ключи аутентификации](https://python-all.ru/3.8/library/multiprocessing.html#authentication-keys)
    - [Логирование](https://python-all.ru/3.8/library/multiprocessing.html#logging)
    - [Модуль `multiprocessing.dummy`](https://python-all.ru/3.8/library/multiprocessing.html#module-multiprocessing.dummy)
  - [Рекомендации по программированию](https://python-all.ru/3.8/library/multiprocessing.html#programming-guidelines)

    - [Все методы запуска](https://python-all.ru/3.8/library/multiprocessing.html#all-start-methods)
    - [Методы запуска *spawn* и *forkserver*](https://python-all.ru/3.8/library/multiprocessing.html#the-spawn-and-forkserver-start-methods)
  - [Примеры](https://python-all.ru/3.8/library/multiprocessing.html#examples)
- [`multiprocessing.shared_memory` – Предоставляет разделяемую память для прямого доступа между процессами](https://python-all.ru/3.8/library/multiprocessing.shared_memory.html)
- [Пакет `concurrent`](https://python-all.ru/3.8/library/concurrent.html)
- [`concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.8/library/concurrent.futures.html)

  - [Объекты исполнителя](https://python-all.ru/3.8/library/concurrent.futures.html#executor-objects)
  - [ThreadPoolExecutor](https://python-all.ru/3.8/library/concurrent.futures.html#threadpoolexecutor)

    - [Пример ThreadPoolExecutor](https://python-all.ru/3.8/library/concurrent.futures.html#threadpoolexecutor-example)
  - [ProcessPoolExecutor](https://python-all.ru/3.8/library/concurrent.futures.html#processpoolexecutor)

    - [Пример ProcessPoolExecutor](https://python-all.ru/3.8/library/concurrent.futures.html#processpoolexecutor-example)
  - [Объекты Future](https://python-all.ru/3.8/library/concurrent.futures.html#future-objects)
  - [Функции модуля](https://python-all.ru/3.8/library/concurrent.futures.html#module-functions)
  - [Классы исключений](https://python-all.ru/3.8/library/concurrent.futures.html#exception-classes)
- [`subprocess` – Управление подпроцессами](https://python-all.ru/3.8/library/subprocess.html)

  - [Использование модуля `subprocess`](https://python-all.ru/3.8/library/subprocess.html#using-the-subprocess-module)

    - [Часто используемые аргументы](https://python-all.ru/3.8/library/subprocess.html#frequently-used-arguments)
    - [Конструктор Popen](https://python-all.ru/3.8/library/subprocess.html#popen-constructor)
    - [Исключения](https://python-all.ru/3.8/library/subprocess.html#exceptions)
  - [Вопросы безопасности](https://python-all.ru/3.8/library/subprocess.html#security-considerations)
  - [Объекты Popen](https://python-all.ru/3.8/library/subprocess.html#popen-objects)
  - [Вспомогательные функции Popen для Windows](https://python-all.ru/3.8/library/subprocess.html#windows-popen-helpers)

    - [Константы Windows](https://python-all.ru/3.8/library/subprocess.html#windows-constants)
  - [Старый высокоуровневый API](https://python-all.ru/3.8/library/subprocess.html#older-high-level-api)
  - [Замена старых функций модулем `subprocess`](https://python-all.ru/3.8/library/subprocess.html#replacing-older-functions-with-the-subprocess-module)

    - [Замена подстановки команд оболочки **/bin/sh**](https://python-all.ru/3.8/library/subprocess.html#replacing-bin-sh-shell-command-substitution)
    - [Замена конвейера оболочки](https://python-all.ru/3.8/library/subprocess.html#replacing-shell-pipeline)
    - [Замена `os.system()`](https://python-all.ru/3.8/library/subprocess.html#replacing-os-system)
    - [Замена семейства `os.spawn`](https://python-all.ru/3.8/library/subprocess.html#replacing-the-os-spawn-family)
    - [Замена `os.popen()`, `os.popen2()`, `os.popen3()`](https://python-all.ru/3.8/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3)
    - [Замена функций из модуля `popen2`](https://python-all.ru/3.8/library/subprocess.html#replacing-functions-from-the-popen2-module)
  - [Устаревшие функции вызова оболочки](https://python-all.ru/3.8/library/subprocess.html#legacy-shell-invocation-functions)
  - [Примечания](https://python-all.ru/3.8/library/subprocess.html#notes)

    - [Преобразование последовательности аргументов в строку на Windows](https://python-all.ru/3.8/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows)
- [`sched` – планировщик событий](https://python-all.ru/3.8/library/sched.html)

  - [Объекты планировщика](https://python-all.ru/3.8/library/sched.html#scheduler-objects)
- [`queue` – класс синхронизированной очереди](https://python-all.ru/3.8/library/queue.html)

  - [Объекты очередей](https://python-all.ru/3.8/library/queue.html#queue-objects)
  - [Объекты SimpleQueue](https://python-all.ru/3.8/library/queue.html#simplequeue-objects)
- [`contextvars` – контекстные переменные](https://python-all.ru/3.8/library/contextvars.html)

  - [Контекстные переменные](https://python-all.ru/3.8/library/contextvars.html#context-variables)
  - [Ручное управление контекстом](https://python-all.ru/3.8/library/contextvars.html#manual-context-management)
  - [Поддержка asyncio](https://python-all.ru/3.8/library/contextvars.html#asyncio-support)

Ниже приведены вспомогательные модули для некоторых из перечисленных выше служб:

- [`_thread` – низкоуровневый API потоков](https://python-all.ru/3.8/library/_thread.html)
- [`_dummy_thread` – прямая замена модуля `_thread`](https://python-all.ru/3.8/library/_dummy_thread.html)
- [`dummy_threading` – прямая замена модуля `threading`](https://python-all.ru/3.8/library/dummy_threading.html)
