동시 실행
*********

이 장에서 설명하는 모듈은 코드의 동시 실행을 지원합니다. 적절한 도구
선택은 실행할 작업(CPU 병목 대 IO 병목)과 선호하는 개발 스타일(이벤트
구동 협력적 다중작업 대 선점적 다중작업)에 따라 달라집니다. 다음은 개
요입니다:

* "threading" --- Thread-based parallelism

  * "active_count()"

  * "current_thread()"

  * "excepthook()"

  * "__excepthook__"

  * "get_ident()"

  * "get_native_id()"

  * "enumerate()"

  * "main_thread()"

  * "settrace()"

  * "settrace_all_threads()"

  * "gettrace()"

  * "setprofile()"

  * "setprofile_all_threads()"

  * "getprofile()"

  * "stack_size()"

  * "TIMEOUT_MAX"

  * 스레드 로컬 데이터

    * "local"

  * Thread 객체

    * "Thread"

      * "start()"

      * "run()"

      * "join()"

      * "name"

      * "getName()"

      * "setName()"

      * "ident"

      * "native_id"

      * "is_alive()"

      * "daemon"

      * "isDaemon()"

      * "setDaemon()"

  * Lock 객체

    * "Lock"

      * "acquire()"

      * "release()"

      * "locked()"

  * RLock 객체

    * "RLock"

      * "acquire()"

      * "release()"

  * Condition 객체

    * "Condition"

      * "acquire()"

      * "release()"

      * "wait()"

      * "wait_for()"

      * "notify()"

      * "notify_all()"

  * Semaphore 객체

    * "Semaphore"

      * "acquire()"

      * "release()"

    * "BoundedSemaphore"

    * "Semaphore" 예

  * Event 객체

    * "Event"

      * "is_set()"

      * "set()"

      * "clear()"

      * "wait()"

  * Timer 객체

    * "Timer"

      * "cancel()"

  * Barrier 객체

    * "Barrier"

      * "wait()"

      * "reset()"

      * "abort()"

      * "parties"

      * "n_waiting"

      * "broken"

    * "BrokenBarrierError"

  * "with" 문으로 록, 조건 및 세마포어 사용하기

* "multiprocessing" --- Process-based parallelism

  * 소개

    * "Process" 클래스

    * 컨텍스트 및 시작 방법

    * 프로세스 간 객체 교환

    * 프로세스 간 동기화

    * 프로세스 간 상태 공유

    * 작업자 풀 사용

  * 레퍼런스

    * "Process"와 예외

      * "Process"

        * "run()"

        * "start()"

        * "join()"

        * "name"

        * "is_alive()"

        * "daemon"

        * "pid"

        * "exitcode"

        * "authkey"

        * "sentinel"

        * "terminate()"

        * "kill()"

        * "close()"

      * "ProcessError"

      * "BufferTooShort"

      * "AuthenticationError"

      * "TimeoutError"

    * 파이프와 큐

      * "Pipe()"

      * "Queue"

        * "qsize()"

        * "empty()"

        * "full()"

        * "put()"

        * "put_nowait()"

        * "get()"

        * "get_nowait()"

        * "close()"

        * "join_thread()"

        * "cancel_join_thread()"

      * "SimpleQueue"

        * "close()"

        * "empty()"

        * "get()"

        * "put()"

      * "JoinableQueue"

        * "task_done()"

        * "join()"

    * 잡동사니

      * "active_children()"

      * "cpu_count()"

      * "current_process()"

      * "parent_process()"

      * "freeze_support()"

      * "get_all_start_methods()"

      * "get_context()"

      * "get_start_method()"

      * "set_executable()"

      * "set_forkserver_preload()"

      * "set_start_method()"

    * Connection 객체

      * "Connection"

        * "send()"

        * "recv()"

        * "fileno()"

        * "close()"

        * "poll()"

        * "send_bytes()"

        * "recv_bytes()"

        * "recv_bytes_into()"

    * 동기화 프리미티브

      * "Barrier"

      * "BoundedSemaphore"

      * "Condition"

      * "Event"

      * "Lock"

        * "acquire()"

        * "release()"

      * "RLock"

        * "acquire()"

        * "release()"

      * "Semaphore"

    * 공유 "ctypes" 객체

      * "Value()"

      * "Array()"

      * "multiprocessing.sharedctypes" 모듈

        * "RawArray()"

        * "RawValue()"

        * "Array()"

        * "Value()"

        * "copy()"

        * "synchronized()"

    * 관리자

      * "Manager()"

      * "BaseManager"

        * "start()"

        * "get_server()"

        * "connect()"

        * "shutdown()"

        * "register()"

        * "address"

      * "SyncManager"

        * "Barrier()"

        * "BoundedSemaphore()"

        * "Condition()"

        * "Event()"

        * "Lock()"

        * "Namespace()"

        * "Queue()"

        * "RLock()"

        * "Semaphore()"

        * "Array()"

        * "Value()"

        * "dict()"

        * "list()"

      * "Namespace"

      * 사용자 정의 관리자

      * 원격 관리자 사용하기

    * 프락시 객체

      * "BaseProxy"

        * "_callmethod()"

        * "_getvalue()"

        * "__repr__()"

        * "__str__()"

      * 정리

    * 프로세스 풀

      * "Pool"

        * "apply()"

        * "apply_async()"

        * "map()"

        * "map_async()"

        * "imap()"

        * "imap_unordered()"

        * "starmap()"

        * "starmap_async()"

        * "close()"

        * "terminate()"

        * "join()"

      * "AsyncResult"

        * "get()"

        * "wait()"

        * "ready()"

        * "successful()"

    * 리스너와 클라이언트

      * "deliver_challenge()"

      * "answer_challenge()"

      * "Client()"

      * "Listener"

        * "accept()"

        * "close()"

        * "address"

        * "last_accepted"

      * "wait()"

      * 주소 형식

    * 인증 키

    * 로깅

      * "get_logger()"

      * "log_to_stderr()"

    * "multiprocessing.dummy" 모듈

      * "ThreadPool"

  * 프로그래밍 지침

    * 모든 시작 방법

    * *spawn* 과 *forkserver* 시작 방법

  * 예제

* "multiprocessing.shared_memory" --- Shared memory for direct access
  across processes

  * "SharedMemory"

    * "close()"

    * "unlink()"

    * "buf"

    * "name"

    * "size"

  * "SharedMemoryManager"

    * "SharedMemory()"

    * "ShareableList()"

  * "ShareableList"

    * "count()"

    * "index()"

    * "format"

    * "shm"

* The "concurrent" package

* "concurrent.futures" --- Launching parallel tasks

  * Executor 객체

    * "Executor"

      * "submit()"

      * "map()"

      * "shutdown()"

  * ThreadPoolExecutor

    * "ThreadPoolExecutor"

    * ThreadPoolExecutor 예제

  * ProcessPoolExecutor

    * "ProcessPoolExecutor"

    * ProcessPoolExecutor 예제

  * Future 객체

    * "Future"

      * "cancel()"

      * "cancelled()"

      * "running()"

      * "done()"

      * "result()"

      * "exception()"

      * "add_done_callback()"

      * "set_running_or_notify_cancel()"

      * "set_result()"

      * "set_exception()"

  * 모듈 함수

    * "wait()"

      * "FIRST_COMPLETED"

      * "FIRST_EXCEPTION"

      * "ALL_COMPLETED"

    * "as_completed()"

  * 예외 클래스

    * "CancelledError"

    * "TimeoutError"

    * "BrokenExecutor"

    * "InvalidStateError"

    * "BrokenThreadPool"

    * "BrokenProcessPool"

* "subprocess" --- Subprocess management

  * "subprocess" 모듈 사용하기

    * "run()"

    * "CompletedProcess"

      * "args"

      * "returncode"

      * "stdout"

      * "stderr"

      * "check_returncode()"

    * "DEVNULL"

    * "PIPE"

    * "STDOUT"

    * "SubprocessError"

    * "TimeoutExpired"

      * "cmd"

      * "timeout"

      * "output"

      * "stdout"

      * "stderr"

    * "CalledProcessError"

      * "returncode"

      * "cmd"

      * "output"

      * "stdout"

      * "stderr"

    * 자주 사용되는 인자

    * Popen 생성자

      * "Popen"

    * 예외

  * 보안 고려 사항

  * Popen 객체

    * "poll()"

    * "wait()"

    * "communicate()"

    * "send_signal()"

    * "terminate()"

    * "kill()"

    * "args"

    * "stdin"

    * "stdout"

    * "stderr"

    * "pid"

    * "returncode"

  * 윈도우 Popen 도우미

    * "STARTUPINFO"

      * "dwFlags"

      * "hStdInput"

      * "hStdOutput"

      * "hStdError"

      * "wShowWindow"

      * "lpAttributeList"

    * 윈도우 상수

      * "STD_INPUT_HANDLE"

      * "STD_OUTPUT_HANDLE"

      * "STD_ERROR_HANDLE"

      * "SW_HIDE"

      * "STARTF_USESTDHANDLES"

      * "STARTF_USESHOWWINDOW"

      * "CREATE_NEW_CONSOLE"

      * "CREATE_NEW_PROCESS_GROUP"

      * "ABOVE_NORMAL_PRIORITY_CLASS"

      * "BELOW_NORMAL_PRIORITY_CLASS"

      * "HIGH_PRIORITY_CLASS"

      * "IDLE_PRIORITY_CLASS"

      * "NORMAL_PRIORITY_CLASS"

      * "REALTIME_PRIORITY_CLASS"

      * "CREATE_NO_WINDOW"

      * "DETACHED_PROCESS"

      * "CREATE_DEFAULT_ERROR_MODE"

      * "CREATE_BREAKAWAY_FROM_JOB"

  * 오래된 고수준 API

    * "call()"

    * "check_call()"

    * "check_output()"

  * 이전 함수를 "subprocess" 모듈로 교체하기

    * **/bin/sh** 셸 명령 치환 교체하기

    * 셸 파이프라인 교체하기

    * "os.system()" 교체하기

    * "os.spawn" 패밀리 교체하기

    * "os.popen()", "os.popen2()", "os.popen3()" 교체하기

    * Replacing functions from the "popen2" module

  * 레거시 셸 호출 함수

    * "getstatusoutput()"

    * "getoutput()"

  * 노트

    * 윈도우에서 인자 시퀀스를 문자열로 변환하기

    * Disabling use of "vfork()" or "posix_spawn()"

* "sched" --- Event scheduler

  * "scheduler"

  * 스케줄러 객체

    * "enterabs()"

    * "enter()"

    * "cancel()"

    * "empty()"

    * "run()"

    * "queue"

* "queue" --- A synchronized queue class

  * "Queue"

  * "LifoQueue"

  * "PriorityQueue"

  * "SimpleQueue"

  * "Empty"

  * "Full"

  * 큐 객체

    * "qsize()"

    * "empty()"

    * "full()"

    * "put()"

    * "put_nowait()"

    * "get()"

    * "get_nowait()"

    * "task_done()"

    * "join()"

  * SimpleQueue 객체

    * "qsize()"

    * "empty()"

    * "put()"

    * "put_nowait()"

    * "get()"

    * "get_nowait()"

* "contextvars" --- Context Variables

  * 컨텍스트 변수

    * "ContextVar"

      * "name"

      * "get()"

      * "set()"

      * "reset()"

    * "Token"

      * "var"

      * "old_value"

      * "MISSING"

  * 수동 컨텍스트 관리

    * "copy_context()"

    * "Context"

      * "run()"

      * "copy()"

      * "get()"

      * "keys()"

      * "values()"

      * "items()"

  * asyncio 지원

다음은 위 서비스 중 일부에 대한 지원 모듈입니다:

* "_thread" --- Low-level threading API

  * "error"

  * "LockType"

  * "start_new_thread()"

  * "interrupt_main()"

  * "exit()"

  * "allocate_lock()"

  * "get_ident()"

  * "get_native_id()"

  * "stack_size()"

  * "TIMEOUT_MAX"

  * "acquire()"

  * "release()"

  * "locked()"
