concurrency.md
1> **Источник:** https://python-all.ru/3.4/library/concurrency.html2>3> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.45---67# 17. Параллельное выполнение89Модули, описанные в этой главе, обеспечивают поддержку параллельного выполнения кода. Выбор подходящего инструмента зависит от выполняемой задачи (с привязкой к ЦП или к вводу-выводу) и предпочитаемого стиля разработки (событийно-ориентированная кооперативная многозадачность или вытесняющая многозадачность). Ниже приведён обзор:1011- [17.1. `threading` – Параллелизм на основе потоков](https://python-all.ru/3.4/library/threading.html)1213 - [17.1.1. Потоково-локальные данные](https://python-all.ru/3.4/library/threading.html#thread-local-data)14 - [17.1.2. Объекты потоков](https://python-all.ru/3.4/library/threading.html#thread-objects)15 - [17.1.3. Объекты блокировок](https://python-all.ru/3.4/library/threading.html#lock-objects)16 - [17.1.4. Объекты RLock](https://python-all.ru/3.4/library/threading.html#rlock-objects)17 - [17.1.5. Объекты Condition](https://python-all.ru/3.4/library/threading.html#condition-objects)18 - [17.1.6. Объекты Semaphore](https://python-all.ru/3.4/library/threading.html#semaphore-objects)1920 - [17.1.6.1. `Semaphore` – Пример](https://python-all.ru/3.4/library/threading.html#semaphore-example)21 - [17.1.7. Объекты Event](https://python-all.ru/3.4/library/threading.html#event-objects)22 - [17.1.8. Объекты Timer](https://python-all.ru/3.4/library/threading.html#timer-objects)23 - [17.1.9. Объекты Barrier](https://python-all.ru/3.4/library/threading.html#barrier-objects)24 - [17.1.10. Использование блокировок, условий и семафоров в операторе `with`](https://python-all.ru/3.4/library/threading.html#using-locks-conditions-and-semaphores-in-the-with-statement)25- [17.2. `multiprocessing` – Параллелизм на основе процессов](https://python-all.ru/3.4/library/multiprocessing.html)2627 - [17.2.1. Введение](https://python-all.ru/3.4/library/multiprocessing.html#introduction)2829 - [17.2.1.1. Класс `Process`](https://python-all.ru/3.4/library/multiprocessing.html#the-process-class)30 - [17.2.1.2. Контексты и методы запуска](https://python-all.ru/3.4/library/multiprocessing.html#contexts-and-start-methods)31 - [17.2.1.3. Обмен объектами между процессами](https://python-all.ru/3.4/library/multiprocessing.html#exchanging-objects-between-processes)32 - [17.2.1.4. Синхронизация между процессами](https://python-all.ru/3.4/library/multiprocessing.html#synchronization-between-processes)33 - [17.2.1.5. Совместное использование состояния между процессами](https://python-all.ru/3.4/library/multiprocessing.html#sharing-state-between-processes)34 - [17.2.1.6. Использование пула рабочих процессов](https://python-all.ru/3.4/library/multiprocessing.html#using-a-pool-of-workers)35 - [17.2.2. Справочная информация](https://python-all.ru/3.4/library/multiprocessing.html#reference)3637 - [17.2.2.1. `Process` и исключения](https://python-all.ru/3.4/library/multiprocessing.html#process-and-exceptions)38 - [17.2.2.2. Каналы и очереди](https://python-all.ru/3.4/library/multiprocessing.html#pipes-and-queues)39 - [17.2.2.3. Разное](https://python-all.ru/3.4/library/multiprocessing.html#miscellaneous)40 - [17.2.2.4. Объекты Connection](https://python-all.ru/3.4/library/multiprocessing.html#connection-objects)41 - [17.2.2.5. Примитивы синхронизации](https://python-all.ru/3.4/library/multiprocessing.html#synchronization-primitives)42 - [17.2.2.6. Общие объекты `ctypes`](https://python-all.ru/3.4/library/multiprocessing.html#shared-ctypes-objects)4344 - [17.2.2.6.1. Модуль `multiprocessing.sharedctypes`](https://python-all.ru/3.4/library/multiprocessing.html#module-multiprocessing.sharedctypes)45 - [17.2.2.7. Менеджеры](https://python-all.ru/3.4/library/multiprocessing.html#managers)4647 - [17.2.2.7.1. Объекты пространства имён](https://python-all.ru/3.4/library/multiprocessing.html#namespace-objects)48 - [17.2.2.7.2. Настраиваемые менеджеры](https://python-all.ru/3.4/library/multiprocessing.html#customized-managers)49 - [17.2.2.7.3. Использование удалённого менеджера](https://python-all.ru/3.4/library/multiprocessing.html#using-a-remote-manager)50 - [17.2.2.8. Объекты-прокси](https://python-all.ru/3.4/library/multiprocessing.html#proxy-objects)5152 - [17.2.2.8.1. Очистка](https://python-all.ru/3.4/library/multiprocessing.html#cleanup)53 - [17.2.2.9. Пулы процессов](https://python-all.ru/3.4/library/multiprocessing.html#module-multiprocessing.pool)54 - [17.2.2.10. Слушатели и клиенты](https://python-all.ru/3.4/library/multiprocessing.html#module-multiprocessing.connection)5556 - [17.2.2.10.1. Форматы адресов](https://python-all.ru/3.4/library/multiprocessing.html#address-formats)57 - [17.2.2.11. Ключи аутентификации](https://python-all.ru/3.4/library/multiprocessing.html#authentication-keys)58 - [17.2.2.12. Логирование](https://python-all.ru/3.4/library/multiprocessing.html#logging)59 - [17.2.2.13. Модуль `multiprocessing.dummy`](https://python-all.ru/3.4/library/multiprocessing.html#module-multiprocessing.dummy)60 - [17.2.3. Рекомендации по программированию](https://python-all.ru/3.4/library/multiprocessing.html#programming-guidelines)6162 - [17.2.3.1. Все методы запуска](https://python-all.ru/3.4/library/multiprocessing.html#all-start-methods)63 - [17.2.3.2. Методы запуска *spawn* и *forkserver*](https://python-all.ru/3.4/library/multiprocessing.html#the-spawn-and-forkserver-start-methods)64 - [17.2.4. Примеры](https://python-all.ru/3.4/library/multiprocessing.html#examples)65- [17.3. Пакет `concurrent`](https://python-all.ru/3.4/library/concurrent.html)66- [17.4. `concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.4/library/concurrent.futures.html)6768 - [17.4.1. Объекты-исполнители](https://python-all.ru/3.4/library/concurrent.futures.html#executor-objects)69 - [17.4.2. ThreadPoolExecutor](https://python-all.ru/3.4/library/concurrent.futures.html#threadpoolexecutor)7071 - [17.4.2.1. Пример ThreadPoolExecutor](https://python-all.ru/3.4/library/concurrent.futures.html#threadpoolexecutor-example)72 - [17.4.3. ProcessPoolExecutor](https://python-all.ru/3.4/library/concurrent.futures.html#processpoolexecutor)7374 - [17.4.3.1. Пример ProcessPoolExecutor](https://python-all.ru/3.4/library/concurrent.futures.html#processpoolexecutor-example)75 - [17.4.4. Объекты Future](https://python-all.ru/3.4/library/concurrent.futures.html#future-objects)76 - [17.4.5. Функции модуля](https://python-all.ru/3.4/library/concurrent.futures.html#module-functions)77 - [17.4.6. Классы исключений](https://python-all.ru/3.4/library/concurrent.futures.html#exception-classes)78- [17.5. `subprocess` – Управление подпроцессами](https://python-all.ru/3.4/library/subprocess.html)7980 - [17.5.1. Использование модуля `subprocess`](https://python-all.ru/3.4/library/subprocess.html#using-the-subprocess-module)8182 - [17.5.1.1. Часто используемые аргументы](https://python-all.ru/3.4/library/subprocess.html#frequently-used-arguments)83 - [17.5.1.2. Конструктор Popen](https://python-all.ru/3.4/library/subprocess.html#popen-constructor)84 - [17.5.1.3. Исключения](https://python-all.ru/3.4/library/subprocess.html#exceptions)85 - [17.5.2. Вопросы безопасности](https://python-all.ru/3.4/library/subprocess.html#security-considerations)86 - [17.5.3. Объекты Popen](https://python-all.ru/3.4/library/subprocess.html#popen-objects)87 - [17.5.4. Вспомогательные средства Popen для Windows](https://python-all.ru/3.4/library/subprocess.html#windows-popen-helpers)8889 - [17.5.4.1. Константы](https://python-all.ru/3.4/library/subprocess.html#constants)90 - [17.5.5. Замена старых функций модулем `subprocess`](https://python-all.ru/3.4/library/subprocess.html#replacing-older-functions-with-the-subprocess-module)9192 - [17.5.5.1. Замена обратных кавычек оболочки /bin/sh](https://python-all.ru/3.4/library/subprocess.html#replacing-bin-sh-shell-backquote)93 - [17.5.5.2. Замена конвейера оболочки](https://python-all.ru/3.4/library/subprocess.html#replacing-shell-pipeline)94 - [17.5.5.3. Замена `os.system()`](https://python-all.ru/3.4/library/subprocess.html#replacing-os-system)95 - [17.5.5.4. Замена семейства `os.spawn`](https://python-all.ru/3.4/library/subprocess.html#replacing-the-os-spawn-family)96 - [17.5.5.5. Замена `os.popen()`, `os.popen2()` и `os.popen3()`](https://python-all.ru/3.4/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3)97 - [17.5.5.6. Замена функций из модуля `popen2`](https://python-all.ru/3.4/library/subprocess.html#replacing-functions-from-the-popen2-module)98 - [17.5.6. Устаревшие функции вызова оболочки](https://python-all.ru/3.4/library/subprocess.html#legacy-shell-invocation-functions)99 - [17.5.7. Примечания](https://python-all.ru/3.4/library/subprocess.html#notes)100101 - [17.5.7.1. Преобразование последовательности аргументов в строку в Windows](https://python-all.ru/3.4/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows)102- [17.6. `sched` – Планировщик событий](https://python-all.ru/3.4/library/sched.html)103104 - [17.6.1. Объекты планировщика](https://python-all.ru/3.4/library/sched.html#scheduler-objects)105- [17.7. `queue` – Синхронизированная очередь](https://python-all.ru/3.4/library/queue.html)106107 - [17.7.1. Объекты очереди](https://python-all.ru/3.4/library/queue.html#queue-objects)108109Ниже приведены вспомогательные модули для некоторых из перечисленных выше служб:110111- [17.8. `dummy_threading` – Замена модуля `threading` без изменений](https://python-all.ru/3.4/library/dummy_threading.html)112- [17.9. `_thread` – Низкоуровневый API многопоточности](https://python-all.ru/3.4/library/_thread.html)113- [17.10. `_dummy_thread` – прямая замена модуля `_thread`](https://python-all.ru/3.4/library/_dummy_thread.html)114