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

---

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

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

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

  - [17.1.1. Потоково-локальные данные](https://python-all.ru/3.3/library/threading.html#thread-local-data)
  - [17.1.2. Объекты потоков](https://python-all.ru/3.3/library/threading.html#thread-objects)
  - [17.1.3. Объекты блокировок](https://python-all.ru/3.3/library/threading.html#lock-objects)
  - [17.1.4. Объекты RLock](https://python-all.ru/3.3/library/threading.html#rlock-objects)
  - [17.1.5. Объекты Condition](https://python-all.ru/3.3/library/threading.html#condition-objects)
  - [17.1.6. Объекты Semaphore](https://python-all.ru/3.3/library/threading.html#semaphore-objects)

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

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

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

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

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

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

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

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

    - [17.2.3.1. Все платформы](https://python-all.ru/3.3/library/multiprocessing.html#all-platforms)
    - [17.2.3.2. Windows](https://python-all.ru/3.3/library/multiprocessing.html#windows)
  - [17.2.4. Примеры](https://python-all.ru/3.3/library/multiprocessing.html#examples)
- [17.3. Пакет `concurrent`](https://python-all.ru/3.3/library/concurrent.html)
- [17.4. `concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.3/library/concurrent.futures.html)

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

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

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

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

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

    - [17.5.3.1. Константы](https://python-all.ru/3.3/library/subprocess.html#constants)
  - [17.5.4. Замена старых функций модулем `подпроцесс`](https://python-all.ru/3.3/library/subprocess.html#replacing-older-functions-with-the-subprocess-module)

    - [17.5.4.1. Замена обратных кавычек оболочки /bin/sh](https://python-all.ru/3.3/library/subprocess.html#replacing-bin-sh-shell-backquote)
    - [17.5.4.2. Замена конвейера оболочки](https://python-all.ru/3.3/library/subprocess.html#replacing-shell-pipeline)
    - [17.5.4.3. Замена `os.system()`](https://python-all.ru/3.3/library/subprocess.html#replacing-os-system)
    - [17.5.4.4. Замена семейства `os.spawn`](https://python-all.ru/3.3/library/subprocess.html#replacing-the-os-spawn-family)
    - [17.5.4.5. Замена `os.popen()`, `os.popen2()`, `os.popen3()`](https://python-all.ru/3.3/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3)
    - [17.5.4.6. Замена функций из модуля `popen2`](https://python-all.ru/3.3/library/subprocess.html#replacing-functions-from-the-popen2-module)
  - [17.5.5. Устаревшие функции вызова оболочки](https://python-all.ru/3.3/library/subprocess.html#legacy-shell-invocation-functions)
  - [17.5.6. Примечания](https://python-all.ru/3.3/library/subprocess.html#notes)

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

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

  - [17.7.1. Объекты очереди](https://python-all.ru/3.3/library/queue.html#queue-objects)
- [17.8. `select` – Ожидание завершения операций ввода-вывода](https://python-all.ru/3.3/library/select.html)

  - [17.8.1. `/dev/poll` Объекты опроса (poll)](https://python-all.ru/3.3/library/select.html#dev-poll-polling-objects)
  - [17.8.2. Объекты опроса по переднему и уровневому фронтам (epoll)](https://python-all.ru/3.3/library/select.html#edge-and-level-trigger-polling-epoll-objects)
  - [17.8.3. Объекты опроса](https://python-all.ru/3.3/library/select.html#polling-objects)
  - [17.8.4. Объекты kqueue](https://python-all.ru/3.3/library/select.html#kqueue-objects)
  - [17.8.5. Объекты kevent](https://python-all.ru/3.3/library/select.html#kevent-objects)

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

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