• <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>
  • <legend id='vW6bt'><style id='vW6bt'><dir id='vW6bt'><q id='vW6bt'></q></dir></style></legend>
  • <tfoot id='vW6bt'></tfoot>

          <bdo id='vW6bt'></bdo><ul id='vW6bt'></ul>
      1. Python 3 中的多处理、多线程和异步

        multiprocessing vs multithreading vs asyncio in Python 3(Python 3 中的多处理、多线程和异步)

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

            1. <legend id='6JJno'><style id='6JJno'><dir id='6JJno'><q id='6JJno'></q></dir></style></legend>
                <tbody id='6JJno'></tbody>
                <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 中的多处理、多线程和异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送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模板网!

                  【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

                  相关文档推荐

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多处理模块的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中将多个参数传递给 pool.map() 函数)
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序员软件开
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多进程池.当其中一个工作进程确定不再需要完成工作时,如何退出脚本?) - IT屋-程序员
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何将队列引用传递给 pool.map_async() 管理的函数?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(与多处理错误的另一个混淆,“模块对象没有属性“f)
                  <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>
                          <tbody id='6oykf'></tbody>
                        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>