Документация Python неофициальный перевод

concurrency.md

120 строк · 12.2 КБ · обычная страница · сырой текст · скачать

1> **Источник:** https://python-all.ru/3.3/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.3/library/threading.html)1213  - [17.1.1. Потоково-локальные данные](https://python-all.ru/3.3/library/threading.html#thread-local-data)14  - [17.1.2. Объекты потоков](https://python-all.ru/3.3/library/threading.html#thread-objects)15  - [17.1.3. Объекты блокировок](https://python-all.ru/3.3/library/threading.html#lock-objects)16  - [17.1.4. Объекты RLock](https://python-all.ru/3.3/library/threading.html#rlock-objects)17  - [17.1.5. Объекты Condition](https://python-all.ru/3.3/library/threading.html#condition-objects)18  - [17.1.6. Объекты Semaphore](https://python-all.ru/3.3/library/threading.html#semaphore-objects)1920    - [17.1.6.1. `Semaphore` – Пример](https://python-all.ru/3.3/library/threading.html#semaphore-example)21  - [17.1.7. Объекты Event](https://python-all.ru/3.3/library/threading.html#event-objects)22  - [17.1.8. Объекты Timer](https://python-all.ru/3.3/library/threading.html#timer-objects)23  - [17.1.9. Объекты Barrier](https://python-all.ru/3.3/library/threading.html#barrier-objects)24  - [17.1.10. Использование блокировок, условий и семафоров в операторе `with`](https://python-all.ru/3.3/library/threading.html#using-locks-conditions-and-semaphores-in-the-with-statement)25- [17.2. `multiprocessing` – Параллелизм на основе процессов](https://python-all.ru/3.3/library/multiprocessing.html)2627  - [17.2.1. Введение](https://python-all.ru/3.3/library/multiprocessing.html#introduction)2829    - [17.2.1.1. Класс `Process`](https://python-all.ru/3.3/library/multiprocessing.html#the-process-class)30    - [17.2.1.2. Обмен объектами между процессами](https://python-all.ru/3.3/library/multiprocessing.html#exchanging-objects-between-processes)31    - [17.2.1.3. Синхронизация между процессами](https://python-all.ru/3.3/library/multiprocessing.html#synchronization-between-processes)32    - [17.2.1.4. Разделение состояния между процессами](https://python-all.ru/3.3/library/multiprocessing.html#sharing-state-between-processes)33    - [17.2.1.5. Использование пула рабочих процессов](https://python-all.ru/3.3/library/multiprocessing.html#using-a-pool-of-workers)34  - [17.2.2. Справочная информация](https://python-all.ru/3.3/library/multiprocessing.html#reference)3536    - [17.2.2.1. `Process` и исключения](https://python-all.ru/3.3/library/multiprocessing.html#process-and-exceptions)37    - [17.2.2.2. Каналы и очереди](https://python-all.ru/3.3/library/multiprocessing.html#pipes-and-queues)38    - [17.2.2.3. Разное](https://python-all.ru/3.3/library/multiprocessing.html#miscellaneous)39    - [17.2.2.4. Объекты Connection](https://python-all.ru/3.3/library/multiprocessing.html#connection-objects)40    - [17.2.2.5. Примитивы синхронизации](https://python-all.ru/3.3/library/multiprocessing.html#synchronization-primitives)41    - [17.2.2.6. Общие объекты `ctypes`](https://python-all.ru/3.3/library/multiprocessing.html#shared-ctypes-objects)4243      - [17.2.2.6.1. Модуль `multiprocessing.sharedctypes`](https://python-all.ru/3.3/library/multiprocessing.html#module-multiprocessing.sharedctypes)44    - [17.2.2.7. Менеджеры](https://python-all.ru/3.3/library/multiprocessing.html#managers)4546      - [17.2.2.7.1. Объекты пространства имён](https://python-all.ru/3.3/library/multiprocessing.html#namespace-objects)47      - [17.2.2.7.2. Настраиваемые менеджеры](https://python-all.ru/3.3/library/multiprocessing.html#customized-managers)48      - [17.2.2.7.3. Использование удалённого менеджера](https://python-all.ru/3.3/library/multiprocessing.html#using-a-remote-manager)49    - [17.2.2.8. Объекты-прокси](https://python-all.ru/3.3/library/multiprocessing.html#proxy-objects)5051      - [17.2.2.8.1. Очистка](https://python-all.ru/3.3/library/multiprocessing.html#cleanup)52    - [17.2.2.9. Пулы процессов](https://python-all.ru/3.3/library/multiprocessing.html#module-multiprocessing.pool)53    - [17.2.2.10. Слушатели и клиенты](https://python-all.ru/3.3/library/multiprocessing.html#module-multiprocessing.connection)5455      - [17.2.2.10.1. Форматы адресов](https://python-all.ru/3.3/library/multiprocessing.html#address-formats)56    - [17.2.2.11. Ключи аутентификации](https://python-all.ru/3.3/library/multiprocessing.html#authentication-keys)57    - [17.2.2.12. Логирование](https://python-all.ru/3.3/library/multiprocessing.html#logging)58    - [17.2.2.13. Модуль `multiprocessing.dummy`](https://python-all.ru/3.3/library/multiprocessing.html#module-multiprocessing.dummy)59  - [17.2.3. Рекомендации по программированию](https://python-all.ru/3.3/library/multiprocessing.html#programming-guidelines)6061    - [17.2.3.1. Все платформы](https://python-all.ru/3.3/library/multiprocessing.html#all-platforms)62    - [17.2.3.2. Windows](https://python-all.ru/3.3/library/multiprocessing.html#windows)63  - [17.2.4. Примеры](https://python-all.ru/3.3/library/multiprocessing.html#examples)64- [17.3. Пакет `concurrent`](https://python-all.ru/3.3/library/concurrent.html)65- [17.4. `concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.3/library/concurrent.futures.html)6667  - [17.4.1. Объекты-исполнители](https://python-all.ru/3.3/library/concurrent.futures.html#executor-objects)68  - [17.4.2. ThreadPoolExecutor](https://python-all.ru/3.3/library/concurrent.futures.html#threadpoolexecutor)6970    - [17.4.2.1. Пример ThreadPoolExecutor](https://python-all.ru/3.3/library/concurrent.futures.html#threadpoolexecutor-example)71  - [17.4.3. ProcessPoolExecutor](https://python-all.ru/3.3/library/concurrent.futures.html#processpoolexecutor)7273    - [17.4.3.1. Пример ProcessPoolExecutor](https://python-all.ru/3.3/library/concurrent.futures.html#processpoolexecutor-example)74  - [17.4.4. Объекты Future](https://python-all.ru/3.3/library/concurrent.futures.html#future-objects)75  - [17.4.5. Функции модуля](https://python-all.ru/3.3/library/concurrent.futures.html#module-functions)76  - [17.4.6. Классы исключений](https://python-all.ru/3.3/library/concurrent.futures.html#exception-classes)77- [17.5. `subprocess` – Управление подпроцессами](https://python-all.ru/3.3/library/subprocess.html)7879  - [17.5.1. Использование модуля `subprocess`](https://python-all.ru/3.3/library/subprocess.html#using-the-subprocess-module)8081    - [17.5.1.1. Часто используемые аргументы](https://python-all.ru/3.3/library/subprocess.html#frequently-used-arguments)82    - [17.5.1.2. Конструктор Popen](https://python-all.ru/3.3/library/subprocess.html#popen-constructor)83    - [17.5.1.3. Исключения](https://python-all.ru/3.3/library/subprocess.html#exceptions)84    - [17.5.1.4. Безопасность](https://python-all.ru/3.3/library/subprocess.html#security)85  - [17.5.2. Объекты Popen](https://python-all.ru/3.3/library/subprocess.html#popen-objects)86  - [17.5.3. Вспомогательные классы Popen для Windows](https://python-all.ru/3.3/library/subprocess.html#windows-popen-helpers)8788    - [17.5.3.1. Константы](https://python-all.ru/3.3/library/subprocess.html#constants)89  - [17.5.4. Замена старых функций модулем `подпроцесс`](https://python-all.ru/3.3/library/subprocess.html#replacing-older-functions-with-the-subprocess-module)9091    - [17.5.4.1. Замена обратных кавычек оболочки /bin/sh](https://python-all.ru/3.3/library/subprocess.html#replacing-bin-sh-shell-backquote)92    - [17.5.4.2. Замена конвейера оболочки](https://python-all.ru/3.3/library/subprocess.html#replacing-shell-pipeline)93    - [17.5.4.3. Замена `os.system()`](https://python-all.ru/3.3/library/subprocess.html#replacing-os-system)94    - [17.5.4.4. Замена семейства `os.spawn`](https://python-all.ru/3.3/library/subprocess.html#replacing-the-os-spawn-family)95    - [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)96    - [17.5.4.6. Замена функций из модуля `popen2`](https://python-all.ru/3.3/library/subprocess.html#replacing-functions-from-the-popen2-module)97  - [17.5.5. Устаревшие функции вызова оболочки](https://python-all.ru/3.3/library/subprocess.html#legacy-shell-invocation-functions)98  - [17.5.6. Примечания](https://python-all.ru/3.3/library/subprocess.html#notes)99100    - [17.5.6.1. Преобразование последовательности аргументов в строку в Windows](https://python-all.ru/3.3/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows)101- [17.6. `sched` – Планировщик событий](https://python-all.ru/3.3/library/sched.html)102103  - [17.6.1. Объекты планировщика](https://python-all.ru/3.3/library/sched.html#scheduler-objects)104- [17.7. `queue` – Синхронизированная очередь](https://python-all.ru/3.3/library/queue.html)105106  - [17.7.1. Объекты очереди](https://python-all.ru/3.3/library/queue.html#queue-objects)107- [17.8. `select` – Ожидание завершения операций ввода-вывода](https://python-all.ru/3.3/library/select.html)108109  - [17.8.1. `/dev/poll` Объекты опроса (poll)](https://python-all.ru/3.3/library/select.html#dev-poll-polling-objects)110  - [17.8.2. Объекты опроса по переднему и уровневому фронтам (epoll)](https://python-all.ru/3.3/library/select.html#edge-and-level-trigger-polling-epoll-objects)111  - [17.8.3. Объекты опроса](https://python-all.ru/3.3/library/select.html#polling-objects)112  - [17.8.4. Объекты kqueue](https://python-all.ru/3.3/library/select.html#kqueue-objects)113  - [17.8.5. Объекты kevent](https://python-all.ru/3.3/library/select.html#kevent-objects)114115Ниже приведены вспомогательные модули для некоторых из перечисленных выше служб:116117- [17.9. `dummy_threading` – Замена модуля `threading` без изменений](https://python-all.ru/3.3/library/dummy_threading.html)118- [17.10. `_thread` – Низкоуровневый API для работы с потоками](https://python-all.ru/3.3/library/_thread.html)119- [17.11. `_dummy_thread` – Замена модуля `_thread` без изменений](https://python-all.ru/3.3/library/_dummy_thread.html)120