mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 06:55:36 +08:00
1 line
16 KiB
HTML
1 line
16 KiB
HTML
<div class="body" role="main"><div class="section" id="concurrent-execution"><h1><span class="yiyi-st" id="yiyi-9">17. </span><span class="yiyi-st" id="yiyi-10">并发执行</span></h1><p><span class="yiyi-st" id="yiyi-11">本章中描述的模块提供了对代码并发执行的支持。</span><span class="yiyi-st" id="yiyi-12">工具的适当选择将取决于要执行的任务(CPU绑定与IO绑定)和首选开发风格(事件驱动的协作多任务与抢占式多任务)。</span><span class="yiyi-st" id="yiyi-13">这里有一个概述:</span></p><div class="toctree-wrapper compound"><ul><li class="toctree-l1"><span class="yiyi-st" id="yiyi-25"><a class="reference internal" href="threading.html">17.1. <code class="docutils literal"><span class="pre">threading</span></code> - 基于线程的并行性</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-14"><a class="reference internal" href="threading.html#thread-local-data">17.1.1.线程本地数据</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-15"><a class="reference internal" href="threading.html#thread-objects">17.1.2.线程对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-16"><a class="reference internal" href="threading.html#lock-objects">17.1.3.锁定对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-17"><a class="reference internal" href="threading.html#rlock-objects">17.1.4. RLock对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-18"><a class="reference internal" href="threading.html#condition-objects">17.1.5.条件对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-20"><a class="reference internal" href="threading.html#semaphore-objects">17.1.6.信号物件</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-19"><a class="reference internal" href="threading.html#semaphore-example">17.1.6.1. <code class="docutils literal"><span class="pre">Semaphore</span></code>示例</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-21"><a class="reference internal" href="threading.html#event-objects">17.1.7.事件对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-22"><a class="reference internal" href="threading.html#timer-objects">17.1.8.计时器对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-23"><a class="reference internal" href="threading.html#barrier-objects"> 17.1.9. 屏障对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-24"><a class="reference internal" href="threading.html#using-locks-conditions-and-semaphores-in-the-with-statement">17.1.10.在<code class="docutils literal"><span class="pre">with</span></code>语句</a>中使用锁,条件和信号量</span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-56"><a class="reference internal" href="multiprocessing.html">17.2. <code class="docutils literal"><span class="pre">multiprocessing</span></code> - 基于进程的并行性</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-32"><a class="reference internal" href="multiprocessing.html#introduction">17.2.1.简介</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-26"><a class="reference internal" href="multiprocessing.html#the-process-class">17.2.1.1. <code class="docutils literal"><span class="pre">Process</span></code>类</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="multiprocessing.html#contexts-and-start-methods">17.2.1.2.上下文和启动方法</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-28"><a class="reference internal" href="multiprocessing.html#exchanging-objects-between-processes">17.2.1.3.在进程之间交换对象</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-29"><a class="reference internal" href="multiprocessing.html#synchronization-between-processes">17.2.1.4.进程间同步</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-30"><a class="reference internal" href="multiprocessing.html#sharing-state-between-processes">17.2.1.5.进程之间共享状态</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-31"><a class="reference internal" href="multiprocessing.html#using-a-pool-of-workers">17.2.1.6.使用工人池</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-51"><a class="reference internal" href="multiprocessing.html#reference">17.2.2.参考</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-33"><a class="reference internal" href="multiprocessing.html#process-and-exceptions">17.2.2.1. <code class="docutils literal"><span class="pre">Process</span></code>和例外</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-34"><a class="reference internal" href="multiprocessing.html#pipes-and-queues">17.2.2.2.管道和队列</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-35"><a class="reference internal" href="multiprocessing.html#miscellaneous">17.2.2.3.杂项</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-36"><a class="reference internal" href="multiprocessing.html#connection-objects">17.2.2.4.连接对象</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="multiprocessing.html#synchronization-primitives">17.2.2.5.同步原语</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-39"><a class="reference internal" href="multiprocessing.html#shared-ctypes-objects">17.2.2.6.共享<code class="docutils literal"><span class="pre">ctypes</span></code>对象</a></span><ul><li class="toctree-l4"><span class="yiyi-st" id="yiyi-38"><a class="reference internal" href="multiprocessing.html#module-multiprocessing.sharedctypes">17.2.2.6.1. <code class="docutils literal"><span class="pre">multiprocessing.sharedctypes</span></code>模块</a></span></li></ul></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-42"><a class="reference internal" href="multiprocessing.html#managers">17.2.2.7.经理</a></span><ul><li class="toctree-l4"><span class="yiyi-st" id="yiyi-40"><a class="reference internal" href="multiprocessing.html#customized-managers">17.2.2.7.1.自定义管理器</a></span></li><li class="toctree-l4"><span class="yiyi-st" id="yiyi-41"><a class="reference internal" href="multiprocessing.html#using-a-remote-manager">17.2.2.7.2.使用远程管理器</a></span></li></ul></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-44"><a class="reference internal" href="multiprocessing.html#proxy-objects">17.2.2.8.代理对象</a></span><ul><li class="toctree-l4"><span class="yiyi-st" id="yiyi-43"><a class="reference internal" href="multiprocessing.html#cleanup">17.2.2.8.1.清理</a></span></li></ul></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-45"><a class="reference internal" href="multiprocessing.html#module-multiprocessing.pool">17.2.2.9.处理池</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-47"><a class="reference internal" href="multiprocessing.html#module-multiprocessing.connection">17.2.2.10.监听器和客户端</a></span><ul><li class="toctree-l4"><span class="yiyi-st" id="yiyi-46"><a class="reference internal" href="multiprocessing.html#address-formats">17.2.2.10.1.地址格式</a></span></li></ul></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-48"><a class="reference internal" href="multiprocessing.html#authentication-keys">17.2.2.11.验证密钥</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-49"><a class="reference internal" href="multiprocessing.html#logging">17.2.2.12.记录</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-50"><a class="reference internal" href="multiprocessing.html#module-multiprocessing.dummy">17.2.2.13. <code class="docutils literal"><span class="pre">multiprocessing.dummy</span></code>模块</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-54"><a class="reference internal" href="multiprocessing.html#programming-guidelines">17.2.3.编程指南</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-52"><a class="reference internal" href="multiprocessing.html#all-start-methods">17.2.3.1.所有开始方法</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-53"><a class="reference internal" href="multiprocessing.html#the-spawn-and-forkserver-start-methods">17.2.3.2. <em>spawn</em>和<em>forkserver</em>启动方法</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-55"><a class="reference internal" href="multiprocessing.html#examples">17.2.4.示例</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-57"><a class="reference internal" href="concurrent.html">17.3. <code class="docutils literal"><span class="pre">concurrent</span></code></a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-66"><a class="reference internal" href="concurrent.futures.html">17.4. <code class="docutils literal"><span class="pre">concurrent.futures</span></code> - 启动并行任务</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-58"><a class="reference internal" href="concurrent.futures.html#executor-objects">17.4.1. Executor对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-60"><a class="reference internal" href="concurrent.futures.html#threadpoolexecutor"> 17.4.2. 的ThreadPoolExecutor T0></a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-59"><a class="reference internal" href="concurrent.futures.html#threadpoolexecutor-example">17.4.2.1. ThreadPoolExecutor示例</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-62"><a class="reference internal" href="concurrent.futures.html#processpoolexecutor"> 17.4.3. ProcessPoolExecutor T0></a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-61"><a class="reference internal" href="concurrent.futures.html#processpoolexecutor-example">17.4.3.1. ProcessPoolExecutor示例</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-63"><a class="reference internal" href="concurrent.futures.html#future-objects">17.4.4.未来对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-64"><a class="reference internal" href="concurrent.futures.html#module-functions">17.4.5.模块功能</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-65"><a class="reference internal" href="concurrent.futures.html#exception-classes">17.4.6.异常类</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-86"><a class="reference internal" href="subprocess.html">17.5. <code class="docutils literal"><span class="pre">subprocess</span></code> - 子进程管理</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-70"><a class="reference internal" href="subprocess.html#using-the-subprocess-module">17.5.1.使用<code class="docutils literal"><span class="pre">subprocess</span></code>模块</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-67"><a class="reference internal" href="subprocess.html#frequently-used-arguments">17.5.1.1.常用参数</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-68"><a class="reference internal" href="subprocess.html#popen-constructor">17.5.1.2. Popen构造函数</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-69"><a class="reference internal" href="subprocess.html#exceptions">17.5.1.3.例外</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-71"><a class="reference internal" href="subprocess.html#security-considerations">17.5.2.安全注意事项</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-72"><a class="reference internal" href="subprocess.html#popen-objects"> 17.5.3. Popen对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-74"><a class="reference internal" href="subprocess.html#windows-popen-helpers">17.5.4. Windows Popen助手</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-73"><a class="reference internal" href="subprocess.html#constants">17.5.4.1.常数</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-75"><a class="reference internal" href="subprocess.html#older-high-level-api">17.5.5.旧版高级API</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-82"><a class="reference internal" href="subprocess.html#replacing-older-functions-with-the-subprocess-module">17.5.6.使用<code class="docutils literal"><span class="pre">subprocess</span></code>模块</a>替换旧功能</span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-76"><a class="reference internal" href="subprocess.html#replacing-bin-sh-shell-backquote">17.5.6.1.替换/ bin / sh shell反引号</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-77"><a class="reference internal" href="subprocess.html#replacing-shell-pipeline">17.5.6.2.更换外壳管道</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-78"><a class="reference internal" href="subprocess.html#replacing-os-system">17.5.6.3.替换<code class="docutils literal"><span class="pre">os.system()</span></code></a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-79"><a class="reference internal" href="subprocess.html#replacing-the-os-spawn-family">17.5.6.4.替换<code class="docutils literal"><span class="pre">os.spawn</span></code>系列</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-80"><a class="reference internal" href="subprocess.html#replacing-os-popen-os-popen2-os-popen3">17.5.6.5.替换<code class="docutils literal"><span class="pre">os.popen()</span></code>,<code class="docutils literal"><span class="pre">os.popen2()</span></code>,<code class="docutils literal"><span class="pre">os.popen3()</span></code></a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-81"><a class="reference internal" href="subprocess.html#replacing-functions-from-the-popen2-module">17.5.6.6.替换<code class="docutils literal"><span class="pre">popen2</span></code>模块</a>中的函数</span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-83"><a class="reference internal" href="subprocess.html#legacy-shell-invocation-functions">17.5.7.旧的Shell调用函数</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-85"><a class="reference internal" href="subprocess.html#notes">17.5.8.注释</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-84"><a class="reference internal" href="subprocess.html#converting-an-argument-sequence-to-a-string-on-windows">17.5.8.1.在Windows上将参数序列转换为字符串</a></span></li></ul></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-88"><a class="reference internal" href="sched.html">17.6. <code class="docutils literal"><span class="pre">sched</span></code> - 事件调度程序</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-87"><a class="reference internal" href="sched.html#scheduler-objects">17.6.1.计划对象</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-90"><a class="reference internal" href="queue.html">17.7. <code class="docutils literal"><span class="pre">queue</span></code> - 同步队列类</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-89"><a class="reference internal" href="queue.html#queue-objects">17.7.1.队列对象</a></span></li></ul></li></ul></div><p><span class="yiyi-st" id="yiyi-91">以下是一些上述服务的支持模块:</span></p><div class="toctree-wrapper compound"><ul><li class="toctree-l1"><span class="yiyi-st" id="yiyi-92"><a class="reference internal" href="dummy_threading.html">17.8. <code class="docutils literal"><span class="pre">dummy_threading</span></code> - <code class="docutils literal"><span class="pre">threading</span></code>模块的插入替换</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-93"><a class="reference internal" href="_thread.html">17.9. <code class="docutils literal"><span class="pre">_thread</span></code> - 低级线程API</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-94"><a class="reference internal" href="_dummy_thread.html">17.10. <code class="docutils literal"><span class="pre">_dummy_thread</span></code> - 替换<code class="docutils literal"><span class="pre">_thread</span></code>模块</a></span></li></ul></div></div></div> |