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

---

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

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

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

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

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

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

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

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

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

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

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

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

    - [17.2.3.1. Все методы запуска](https://python-all.ru/3.5/library/multiprocessing.html#all-start-methods)
    - [17.2.3.2. Методы запуска *spawn* и *forkserver*](https://python-all.ru/3.5/library/multiprocessing.html#the-spawn-and-forkserver-start-methods)
  - [17.2.4. Примеры](https://python-all.ru/3.5/library/multiprocessing.html#examples)
- [17.3. Пакет `concurrent`](https://python-all.ru/3.5/library/concurrent.html)
- [17.4. `concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.5/library/concurrent.futures.html)

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

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

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

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

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

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

    - [17.5.6.1. Замена обратных кавычек оболочки /bin/sh](https://python-all.ru/3.5/library/subprocess.html#replacing-bin-sh-shell-backquote)
    - [17.5.6.2. Замена конвейера оболочки](https://python-all.ru/3.5/library/subprocess.html#replacing-shell-pipeline)
    - [17.5.6.3. Замена `os.system()`](https://python-all.ru/3.5/library/subprocess.html#replacing-os-system)
    - [17.5.6.4. Замена семейства `os.spawn`](https://python-all.ru/3.5/library/subprocess.html#replacing-the-os-spawn-family)
    - [17.5.6.5. Замена `os.popen()`, `os.popen2()`, `os.popen3()`](https://python-all.ru/3.5/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3)
    - [17.5.6.6. Замена функций модуля `popen2`](https://python-all.ru/3.5/library/subprocess.html#replacing-functions-from-the-popen2-module)
  - [17.5.7. Устаревшие функции вызова оболочки](https://python-all.ru/3.5/library/subprocess.html#legacy-shell-invocation-functions)
  - [17.5.8. Примечания](https://python-all.ru/3.5/library/subprocess.html#notes)

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

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

  - [17.7.1. Объекты очереди](https://python-all.ru/3.5/library/queue.html#queue-objects)

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

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