1. <small id='9HACl'></small><noframes id='9HACl'>

    • <bdo id='9HACl'></bdo><ul id='9HACl'></ul>
    <tfoot id='9HACl'></tfoot>

    <legend id='9HACl'><style id='9HACl'><dir id='9HACl'><q id='9HACl'></q></dir></style></legend>

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

      可以从 IDLE 运行多处理进程类吗

      时间:2023-05-27
        <i id='IdO6Y'><tr id='IdO6Y'><dt id='IdO6Y'><q id='IdO6Y'><span id='IdO6Y'><b id='IdO6Y'><form id='IdO6Y'><ins id='IdO6Y'></ins><ul id='IdO6Y'></ul><sub id='IdO6Y'></sub></form><legend id='IdO6Y'></legend><bdo id='IdO6Y'><pre id='IdO6Y'><center id='IdO6Y'></center></pre></bdo></b><th id='IdO6Y'></th></span></q></dt></tr></i><div id='IdO6Y'><tfoot id='IdO6Y'></tfoot><dl id='IdO6Y'><fieldset id='IdO6Y'></fieldset></dl></div>
        <legend id='IdO6Y'><style id='IdO6Y'><dir id='IdO6Y'><q id='IdO6Y'></q></dir></style></legend>

            <tbody id='IdO6Y'></tbody>
        • <tfoot id='IdO6Y'></tfoot>
              • <bdo id='IdO6Y'></bdo><ul id='IdO6Y'></ul>

                <small id='IdO6Y'></small><noframes id='IdO6Y'>

                本文介绍了可以从 IDLE 运行多处理进程类吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                多处理进程类的基本示例在从文件执行时运行,而不是从 IDLE 执行.为什么会这样,能做到吗?

                A basic example of multiprocessing Process class runs when executed from file, but not from IDLE. Why is that and can it be done?

                from multiprocessing import Process
                
                def f(name):
                    print('hello', name)
                
                p = Process(target=f, args=('bob',))
                p.start()
                p.join()
                

                推荐答案

                是的.该函数中的以下工作 f 在单独的(第三个)进程中运行.

                Yes. The following works in that function f is run in a separate (third) process.

                from multiprocessing import Process
                
                def f(name):
                    print('hello', name)
                
                if __name__ == '__main__':
                    p = Process(target=f, args=('bob',))
                    p.start()
                    p.join()
                

                但是,要查看 print 输出,至少在 Windows 上,必须从这样的控制台启动 IDLE.

                However, to see the print output, at least on Windows, one must start IDLE from a console like so.

                C:UsersTerry>python -m idlelib
                hello bob
                

                (在 2.x 上使用 idlelib.idle.)原因是 IDLE 在单独的进程中运行用户代码.目前,IDLE 进程和用户代码进程之间的连接是通过套接字进行的.多处理完成的分叉不会复制或继承套接字连接.通过图标或资源管理器(在 Windows 中)启动 IDLE 时,打印输出无处可去.当使用 python(而不是 pythonw)从控制台启动时,输出将进入控制台,如上.

                (Use idlelib.idle on 2.x.) The reason is that IDLE runs user code in a separate process. Currently the connection between the IDLE process and the user code process is via a socket. The fork done by multiprocessing does not duplicate or inherit the socket connection. When IDLE is started via an icon or Explorer (in Windows), there is nowhere for the print output to go. When started from a console with python (rather than pythonw), output goes to the console, as above.

                这篇关于可以从 IDLE 运行多处理进程类吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用多处理从不同的进程追加到同一个列表 下一篇:我可以在 Pool.imap 调用的函数中使用多处理队列吗

                相关文章

                最新文章

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

                    • <bdo id='f66KV'></bdo><ul id='f66KV'></ul>

                    <tfoot id='f66KV'></tfoot>

                  1. <legend id='f66KV'><style id='f66KV'><dir id='f66KV'><q id='f66KV'></q></dir></style></legend>

                    <small id='f66KV'></small><noframes id='f66KV'>