1. <small id='6JJno'></small><noframes id='6JJno'>

    1. <legend id='6JJno'><style id='6JJno'><dir id='6JJno'><q id='6JJno'></q></dir></style></legend>
      <tfoot id='6JJno'></tfoot>
        <bdo id='6JJno'></bdo><ul id='6JJno'></ul>

      <i id='6JJno'><tr id='6JJno'><dt id='6JJno'><q id='6JJno'><span id='6JJno'><b id='6JJno'><form id='6JJno'><ins id='6JJno'></ins><ul id='6JJno'></ul><sub id='6JJno'></sub></form><legend id='6JJno'></legend><bdo id='6JJno'><pre id='6JJno'><center id='6JJno'></center></pre></bdo></b><th id='6JJno'></th></span></q></dt></tr></i><div id='6JJno'><tfoot id='6JJno'></tfoot><dl id='6JJno'><fieldset id='6JJno'></fieldset></dl></div>

      Python 3 中的多处理、多线程和异步

      时间:2023-05-26
    2. <small id='vW6bt'></small><noframes id='vW6bt'>

      <i id='vW6bt'><tr id='vW6bt'><dt id='vW6bt'><q id='vW6bt'><span id='vW6bt'><b id='vW6bt'><form id='vW6bt'><ins id='vW6bt'></ins><ul id='vW6bt'></ul><sub id='vW6bt'></sub></form><legend id='vW6bt'></legend><bdo id='vW6bt'><pre id='vW6bt'><center id='vW6bt'></center></pre></bdo></b><th id='vW6bt'></th></span></q></dt></tr></i><div id='vW6bt'><tfoot id='vW6bt'></tfoot><dl id='vW6bt'><fieldset id='vW6bt'></fieldset></dl></div>
    3. <legend id='vW6bt'><style id='vW6bt'><dir id='vW6bt'><q id='vW6bt'></q></dir></style></legend>
        <tbody id='vW6bt'></tbody>

      • <tfoot id='vW6bt'></tfoot>

              <bdo id='vW6bt'></bdo><ul id='vW6bt'></ul>
              • 本文介绍了Python 3 中的多处理、多线程和异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我发现在 Python 3.4 中有几个不同的多处理/线程库:multiprocessing vs 线程 vs asyncio.

                I found that in Python 3.4 there are few different libraries for multiprocessing/threading: multiprocessing vs threading vs asyncio.

                但我不知道该使用哪一个或者是推荐的".他们做同样的事情,还是不同?如果是这样,哪一个用于什么?我想在我的计算机上编写一个使用多核的程序.但我不知道我应该学习哪个库.

                But I don't know which one to use or is the "recommended one". Do they do the same thing, or are different? If so, which one is used for what? I want to write a program that uses multicores in my computer. But I don't know which library I should learn.

                推荐答案

                它们用于(稍微)不同的目的和/或要求.CPython(一个典型的主线 Python 实现)仍然具有 全局解释器锁,因此是一个多线程应用程序(现在实现并行处理的标准方法)不是最理想的.这就是为什么 multiprocessing 可能 优于 threading 的原因.但并不是每个问题都可以有效地分解为[几乎独立的]部分,因此可能需要繁重的进程间通信.这就是为什么 multiprocessing 通常可能不优于 threading.

                They are intended for (slightly) different purposes and/or requirements. CPython (a typical, mainline Python implementation) still has the global interpreter lock so a multi-threaded application (a standard way to implement parallel processing nowadays) is suboptimal. That's why multiprocessing may be preferred over threading. But not every problem may be effectively split into [almost independent] pieces, so there may be a need in heavy interprocess communications. That's why multiprocessing may not be preferred over threading in general.

                asyncio(这种技术不仅在 Python 中可用,其他语言和/或框架也有它,例如 Boost.ASIO) 是一种有效处理来自许多同时源的大量 I/O 操作而无需并行代码执行的方法.所以它只是针对特定任务的解决方案(确实是一个很好的解决方案!),而不是一般的并行处理.

                asyncio (this technique is available not only in Python, other languages and/or frameworks also have it, e.g. Boost.ASIO) is a method to effectively handle a lot of I/O operations from many simultaneous sources w/o need of parallel code execution. So it's just a solution (a good one indeed!) for a particular task, not for parallel processing in general.

                这篇关于Python 3 中的多处理、多线程和异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:multiprocessing.Pool 似乎可以在 Windows 中工作,但不 下一篇:将 100% 的内核与多处理模块一起使用

                相关文章

                最新文章

                <tfoot id='6oykf'></tfoot>
                1. <small id='6oykf'></small><noframes id='6oykf'>

                  <legend id='6oykf'><style id='6oykf'><dir id='6oykf'><q id='6oykf'></q></dir></style></legend>
                  1. <i id='6oykf'><tr id='6oykf'><dt id='6oykf'><q id='6oykf'><span id='6oykf'><b id='6oykf'><form id='6oykf'><ins id='6oykf'></ins><ul id='6oykf'></ul><sub id='6oykf'></sub></form><legend id='6oykf'></legend><bdo id='6oykf'><pre id='6oykf'><center id='6oykf'></center></pre></bdo></b><th id='6oykf'></th></span></q></dt></tr></i><div id='6oykf'><tfoot id='6oykf'></tfoot><dl id='6oykf'><fieldset id='6oykf'></fieldset></dl></div>
                      <bdo id='6oykf'></bdo><ul id='6oykf'></ul>