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

concurrency.md

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

1> **Источник:** https://python-all.ru/3.14/library/concurrency.html2>3> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.45---67# Параллельное выполнение89Модули, описанные в этой главе, обеспечивают поддержку параллельного выполнения кода. Выбор подходящего инструмента зависит от выполняемой задачи (с привязкой к ЦП или к вводу-выводу) и предпочитаемого стиля разработки (событийно-ориентированная кооперативная многозадачность или вытесняющая многозадачность). Ниже приведён обзор:1011- [`threading` – параллелизм на основе потоков](https://python-all.ru/3.14/library/threading.html)1213  - [Введение](https://python-all.ru/3.14/library/threading.html#introduction)14  - [GIL и соображения производительности](https://python-all.ru/3.14/library/threading.html#gil-and-performance-considerations)15  - [Справочник](https://python-all.ru/3.14/library/threading.html#reference)1617    - [Данные, локальные для потока](https://python-all.ru/3.14/library/threading.html#thread-local-data)18    - [Объекты потоков](https://python-all.ru/3.14/library/threading.html#thread-objects)19    - [Объекты блокировок](https://python-all.ru/3.14/library/threading.html#lock-objects)20    - [Объекты RLock](https://python-all.ru/3.14/library/threading.html#rlock-objects)21    - [Объекты условия](https://python-all.ru/3.14/library/threading.html#condition-objects)22    - [Объекты семафоров](https://python-all.ru/3.14/library/threading.html#semaphore-objects)23    - [Пример `Semaphore`](https://python-all.ru/3.14/library/threading.html#semaphore-example)24    - [Объекты событий](https://python-all.ru/3.14/library/threading.html#event-objects)25    - [Объекты таймеров](https://python-all.ru/3.14/library/threading.html#timer-objects)26    - [Объекты барьеров](https://python-all.ru/3.14/library/threading.html#barrier-objects)27  - [Использование блокировок, условий и семафоров в операторе `with`](https://python-all.ru/3.14/library/threading.html#using-locks-conditions-and-semaphores-in-the-with-statement)28- [`multiprocessing` – параллелизм на основе процессов](https://python-all.ru/3.14/library/multiprocessing.html)2930  - [Введение](https://python-all.ru/3.14/library/multiprocessing.html#introduction)3132    - [Класс `Process`](https://python-all.ru/3.14/library/multiprocessing.html#the-process-class)33    - [Контексты и методы запуска](https://python-all.ru/3.14/library/multiprocessing.html#contexts-and-start-methods)34    - [Обмен объектами между процессами](https://python-all.ru/3.14/library/multiprocessing.html#exchanging-objects-between-processes)35    - [Синхронизация между процессами](https://python-all.ru/3.14/library/multiprocessing.html#synchronization-between-processes)36    - [Совместное использование состояния между процессами](https://python-all.ru/3.14/library/multiprocessing.html#sharing-state-between-processes)37    - [Использование пула рабочих процессов](https://python-all.ru/3.14/library/multiprocessing.html#using-a-pool-of-workers)38  - [Справочник](https://python-all.ru/3.14/library/multiprocessing.html#reference)3940    - [Глобальный метод запуска](https://python-all.ru/3.14/library/multiprocessing.html#global-start-method)41    - [`Process` и исключения](https://python-all.ru/3.14/library/multiprocessing.html#process-and-exceptions)42    - [Каналы и очереди](https://python-all.ru/3.14/library/multiprocessing.html#pipes-and-queues)43    - [Разное](https://python-all.ru/3.14/library/multiprocessing.html#miscellaneous)44    - [Объекты соединений](https://python-all.ru/3.14/library/multiprocessing.html#connection-objects)45    - [Примитивы синхронизации](https://python-all.ru/3.14/library/multiprocessing.html#synchronization-primitives)46    - [Разделяемые `ctypes` объекты](https://python-all.ru/3.14/library/multiprocessing.html#shared-ctypes-objects)4748      - [Модуль `multiprocessing.sharedctypes`](https://python-all.ru/3.14/library/multiprocessing.html#module-multiprocessing.sharedctypes)49    - [Менеджеры](https://python-all.ru/3.14/library/multiprocessing.html#managers)5051      - [Настраиваемые менеджеры](https://python-all.ru/3.14/library/multiprocessing.html#customized-managers)52      - [Использование удалённого менеджера](https://python-all.ru/3.14/library/multiprocessing.html#using-a-remote-manager)53    - [Объекты-прокси](https://python-all.ru/3.14/library/multiprocessing.html#proxy-objects)5455      - [Очистка](https://python-all.ru/3.14/library/multiprocessing.html#cleanup)56    - [Пулы процессов](https://python-all.ru/3.14/library/multiprocessing.html#module-multiprocessing.pool)57    - [Слушатели и клиенты](https://python-all.ru/3.14/library/multiprocessing.html#module-multiprocessing.connection)5859      - [Форматы адресов](https://python-all.ru/3.14/library/multiprocessing.html#address-formats)60    - [Ключи аутентификации](https://python-all.ru/3.14/library/multiprocessing.html#authentication-keys)61    - [Логирование](https://python-all.ru/3.14/library/multiprocessing.html#logging)62    - [Модуль `multiprocessing.dummy`](https://python-all.ru/3.14/library/multiprocessing.html#module-multiprocessing.dummy)63  - [Рекомендации по программированию](https://python-all.ru/3.14/library/multiprocessing.html#programming-guidelines)6465    - [Все методы запуска](https://python-all.ru/3.14/library/multiprocessing.html#all-start-methods)66    - [Методы запуска *spawn* и *forkserver*](https://python-all.ru/3.14/library/multiprocessing.html#the-spawn-and-forkserver-start-methods)67  - [Примеры](https://python-all.ru/3.14/library/multiprocessing.html#examples)68- [`multiprocessing.shared_memory` – Разделяемая память для прямого доступа между процессами](https://python-all.ru/3.14/library/multiprocessing.shared_memory.html)69- [Пакет `concurrent`](https://python-all.ru/3.14/library/concurrent.html)70- [`concurrent.futures` – Запуск параллельных задач](https://python-all.ru/3.14/library/concurrent.futures.html)7172  - [Объекты исполнителя](https://python-all.ru/3.14/library/concurrent.futures.html#executor-objects)73  - [ThreadPoolExecutor](https://python-all.ru/3.14/library/concurrent.futures.html#threadpoolexecutor)7475    - [Пример ThreadPoolExecutor](https://python-all.ru/3.14/library/concurrent.futures.html#threadpoolexecutor-example)76  - [InterpreterPoolExecutor](https://python-all.ru/3.14/library/concurrent.futures.html#interpreterpoolexecutor)77  - [ProcessPoolExecutor](https://python-all.ru/3.14/library/concurrent.futures.html#processpoolexecutor)7879    - [Пример ProcessPoolExecutor](https://python-all.ru/3.14/library/concurrent.futures.html#processpoolexecutor-example)80  - [Объекты Future](https://python-all.ru/3.14/library/concurrent.futures.html#future-objects)81  - [Функции модуля](https://python-all.ru/3.14/library/concurrent.futures.html#module-functions)82  - [Классы исключений](https://python-all.ru/3.14/library/concurrent.futures.html#exception-classes)83- [`concurrent.interpreters` – Несколько интерпретаторов в одном процессе](https://python-all.ru/3.14/library/concurrent.interpreters.html)8485  - [Ключевые детали](https://python-all.ru/3.14/library/concurrent.interpreters.html#key-details)86  - [Введение](https://python-all.ru/3.14/library/concurrent.interpreters.html#introduction)8788    - [Несколько интерпретаторов и изоляция](https://python-all.ru/3.14/library/concurrent.interpreters.html#multiple-interpreters-and-isolation)89    - [Запуск в интерпретаторе](https://python-all.ru/3.14/library/concurrent.interpreters.html#running-in-an-interpreter)90    - [Конкурентность и параллелизм](https://python-all.ru/3.14/library/concurrent.interpreters.html#concurrency-and-parallelism)91    - [Взаимодействие между интерпретаторами](https://python-all.ru/3.14/library/concurrent.interpreters.html#communication-between-interpreters)92    - [«Совместное использование» объектов](https://python-all.ru/3.14/library/concurrent.interpreters.html#sharing-objects)93  - [Справочник](https://python-all.ru/3.14/library/concurrent.interpreters.html#reference)9495    - [Объекты интерпретатора](https://python-all.ru/3.14/library/concurrent.interpreters.html#interpreter-objects)96    - [Исключения](https://python-all.ru/3.14/library/concurrent.interpreters.html#exceptions)97    - [Взаимодействие между интерпретаторами](https://python-all.ru/3.14/library/concurrent.interpreters.html#communicating-between-interpreters)98  - [Основы использования](https://python-all.ru/3.14/library/concurrent.interpreters.html#basic-usage)99- [`subprocess` – Управление подпроцессами](https://python-all.ru/3.14/library/subprocess.html)100101  - [Использование модуля `subprocess`](https://python-all.ru/3.14/library/subprocess.html#using-the-subprocess-module)102103    - [Часто используемые аргументы](https://python-all.ru/3.14/library/subprocess.html#frequently-used-arguments)104    - [Конструктор Popen](https://python-all.ru/3.14/library/subprocess.html#popen-constructor)105    - [Исключения](https://python-all.ru/3.14/library/subprocess.html#exceptions)106  - [Вопросы безопасности](https://python-all.ru/3.14/library/subprocess.html#security-considerations)107  - [Объекты Popen](https://python-all.ru/3.14/library/subprocess.html#popen-objects)108  - [Вспомогательные функции Popen для Windows](https://python-all.ru/3.14/library/subprocess.html#windows-popen-helpers)109110    - [Константы Windows](https://python-all.ru/3.14/library/subprocess.html#windows-constants)111  - [Старый высокоуровневый API](https://python-all.ru/3.14/library/subprocess.html#older-high-level-api)112  - [Замена старых функций модулем `subprocess`](https://python-all.ru/3.14/library/subprocess.html#replacing-older-functions-with-the-subprocess-module)113114    - [Замена подстановки команд оболочки **/bin/sh**](https://python-all.ru/3.14/library/subprocess.html#replacing-bin-sh-shell-command-substitution)115    - [Замена конвейера оболочки](https://python-all.ru/3.14/library/subprocess.html#replacing-shell-pipeline)116    - [Замена `os.system()`](https://python-all.ru/3.14/library/subprocess.html#replacing-os-system)117    - [Замена семейства `os.spawn`](https://python-all.ru/3.14/library/subprocess.html#replacing-the-os-spawn-family)118    - [Замена `os.popen()`](https://python-all.ru/3.14/library/subprocess.html#replacing-os-popen)119  - [Устаревшие функции вызова оболочки](https://python-all.ru/3.14/library/subprocess.html#legacy-shell-invocation-functions)120  - [Примечания](https://python-all.ru/3.14/library/subprocess.html#notes)121122    - [Поведение при тайм-ауте](https://python-all.ru/3.14/library/subprocess.html#timeout-behavior)123    - [Преобразование последовательности аргументов в строку на Windows](https://python-all.ru/3.14/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows)124    - [Отключение использования `posix_spawn()`](https://python-all.ru/3.14/library/subprocess.html#disable-use-of-posix-spawn)125- [`sched` – планировщик событий](https://python-all.ru/3.14/library/sched.html)126127  - [Объекты планировщика](https://python-all.ru/3.14/library/sched.html#scheduler-objects)128- [`queue` – класс синхронизированной очереди](https://python-all.ru/3.14/library/queue.html)129130  - [Объекты очередей](https://python-all.ru/3.14/library/queue.html#queue-objects)131132    - [Ожидание завершения задачи](https://python-all.ru/3.14/library/queue.html#waiting-for-task-completion)133    - [Завершение очередей](https://python-all.ru/3.14/library/queue.html#terminating-queues)134  - [Объекты SimpleQueue](https://python-all.ru/3.14/library/queue.html#simplequeue-objects)135- [`contextvars` – контекстные переменные](https://python-all.ru/3.14/library/contextvars.html)136137  - [Контекстные переменные](https://python-all.ru/3.14/library/contextvars.html#context-variables)138  - [Ручное управление контекстом](https://python-all.ru/3.14/library/contextvars.html#manual-context-management)139  - [Поддержка asyncio](https://python-all.ru/3.14/library/contextvars.html#asyncio-support)140141Ниже приведены вспомогательные модули для некоторых из перечисленных выше служб:142143- [`_thread` – низкоуровневый API потоков](https://python-all.ru/3.14/library/_thread.html)144