久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    1. <small id='QB7Yu'></small><noframes id='QB7Yu'>

      <tfoot id='QB7Yu'></tfoot>

        <bdo id='QB7Yu'></bdo><ul id='QB7Yu'></ul>

      Spyder中的簡(jiǎn)單Python多處理函數(shù)不輸出結(jié)果

      Simple Python Multiprocessing function in Spyder doesn#39;t output results(Spyder中的簡(jiǎn)單Python多處理函數(shù)不輸出結(jié)果)
      <tfoot id='cb2dt'></tfoot>
      <i id='cb2dt'><tr id='cb2dt'><dt id='cb2dt'><q id='cb2dt'><span id='cb2dt'><b id='cb2dt'><form id='cb2dt'><ins id='cb2dt'></ins><ul id='cb2dt'></ul><sub id='cb2dt'></sub></form><legend id='cb2dt'></legend><bdo id='cb2dt'><pre id='cb2dt'><center id='cb2dt'></center></pre></bdo></b><th id='cb2dt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='cb2dt'><tfoot id='cb2dt'></tfoot><dl id='cb2dt'><fieldset id='cb2dt'></fieldset></dl></div>

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

    2. <legend id='cb2dt'><style id='cb2dt'><dir id='cb2dt'><q id='cb2dt'></q></dir></style></legend>

        <tbody id='cb2dt'></tbody>

        • <bdo id='cb2dt'></bdo><ul id='cb2dt'></ul>
                本文介紹了Spyder中的簡(jiǎn)單Python多處理函數(shù)不輸出結(jié)果的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                限時(shí)送ChatGPT賬號(hào)..

                我在這里有一個(gè)非常簡(jiǎn)單的函數(shù),我試圖在其中運(yùn)行和測(cè)試,但是,它不輸出任何內(nèi)容,也沒有任何錯(cuò)誤.我已經(jīng)多次檢查代碼,但沒有任何錯(cuò)誤.

                I have this very simple function right here in which I'm trying to run and test on, however, it doesn't output anything and it doesn't have any errors either. I've checked the code multiple times but it doesn't have any errors.

                我打印了作業(yè),結(jié)果如下:

                I printed jobs and here's what I got:

                [<Process(Process-12, stopped[1])>, 
                <Process(Process-13, stopped[1])>,
                <Process(Process-14, stopped[1])>, 
                <Process(Process-15, stopped[1])>,
                <Process(Process-16, stopped[1])>]
                

                代碼如下:

                import multiprocessing
                
                def worker(num):
                    print "worker ", num
                    return
                
                jobs = []
                for i in range(5):
                    p = multiprocessing.Process(target = worker, args = (i,))
                    jobs.append(p)
                    p.start()
                

                這是我期待的結(jié)果,但它沒有輸出任何東西:

                Here's the result I'm expecting but it's not outputting anything:

                Worker: 0
                Worker: 1
                Worker: 2
                Worker: 3
                Worker: 4
                

                推薦答案

                評(píng)論顯示 OP 使用 Windows 和 Spyder.由于 Spyder 重定向 stdout 而 Windows 不支持 forking,新的子進(jìn)程不會(huì)打印到 Spyder 控制臺(tái).這僅僅是因?yàn)樾伦舆M(jìn)程的 stdout 是 Python 的 vanilla stdout,也可以在 sys.__stdout__ 中找到.

                The comments revealed that OP uses Windows as well as Spyder. Since Spyder redirects stdout and Windows does not support forking, a new child process won't print into the Spyder console. This is simply due to the fact that stdout of the new child process is Python's vanilla stdout, which can also be found in sys.__stdout__.

                有兩種選擇:

                1. 使用 logging 模塊.這將包括創(chuàng)建所有消息并將其記錄到一個(gè)或多個(gè)文件中.使用單個(gè)日志文件可能會(huì)導(dǎo)致輸出稍微亂碼的問(wèn)題,因?yàn)檫M(jìn)程會(huì)同時(shí)寫入文件.每個(gè)進(jìn)程使用一個(gè)文件可以解決這個(gè)問(wèn)題.

                1. Using the logging module. This would encompass creating and logging all messages to one or several files. Using a single log-file may lead to the problem that the output is slightly garbled since the processes would write concurrently to the file. Using a single file per process could solve this.

                不在子進(jìn)程中使用print,而只是將結(jié)果返回給主進(jìn)程.通過(guò)使用 queue (或 multiprocessing.Manager().Queue() 因?yàn)榉植媸遣豢赡艿?或更簡(jiǎn)單地依靠 多處理池的 map 功能,請(qǐng)參見下面的示例.

                Not using print within the child processes, but simply returning the result to the main process. Either by using a queue (or multiprocessing.Manager().Queue() since forking is not possible) or more simply by relying on the multiprocessing Pool's map functionality, see example below.

                帶有池的多處理示例:

                import multiprocessing
                
                def worker(num):
                    """Returns the string of interest"""
                    return "worker %d" % num
                
                def main():
                    pool = multiprocessing.Pool(4)
                    results = pool.map(worker, range(10))
                
                    pool.close()
                    pool.join()
                
                    for result in results:
                        # prints the result string in the main process
                        print(result)
                
                if __name__ == '__main__':
                    # Better protect your main function when you use multiprocessing
                    main()
                

                哪個(gè)打印(在主進(jìn)程中)

                which prints (in the main process)

                worker 0
                worker 1
                worker 2
                worker 3
                worker 4
                worker 5
                worker 6
                worker 7
                worker 8
                worker 9
                

                <小時(shí)>

                如果您迫不及待地等待 map 函數(shù)完成,您可以使用 imap_unordered 并稍微更改命令的順序立即打印結(jié)果:


                If you are to impatient to wait for the map function to finish, you can immediately print your results by using imap_unordered and slightly changing the order of the commands:

                def main():
                    pool = multiprocessing.Pool(4)
                    results = pool.imap_unordered(worker, range(10))
                
                    for result in results:
                        # prints the result string in the main process as soon as say are ready
                        # but results are now no longer in order!
                        print(result)
                
                    # The pool should join after printing all results
                    pool.close()
                    pool.join()
                

                這篇關(guān)于Spyder中的簡(jiǎn)單Python多處理函數(shù)不輸出結(jié)果的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                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 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒有屬性“f)

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

                1. <tfoot id='nCRtA'></tfoot>
                    <bdo id='nCRtA'></bdo><ul id='nCRtA'></ul>
                  • <i id='nCRtA'><tr id='nCRtA'><dt id='nCRtA'><q id='nCRtA'><span id='nCRtA'><b id='nCRtA'><form id='nCRtA'><ins id='nCRtA'></ins><ul id='nCRtA'></ul><sub id='nCRtA'></sub></form><legend id='nCRtA'></legend><bdo id='nCRtA'><pre id='nCRtA'><center id='nCRtA'></center></pre></bdo></b><th id='nCRtA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nCRtA'><tfoot id='nCRtA'></tfoot><dl id='nCRtA'><fieldset id='nCRtA'></fieldset></dl></div>
                            <tbody id='nCRtA'></tbody>

                        • <legend id='nCRtA'><style id='nCRtA'><dir id='nCRtA'><q id='nCRtA'></q></dir></style></legend>
                          主站蜘蛛池模板: 亚洲国产高清高潮精品美女 | 日韩欧美在线观看 | 午夜欧美 | 成人天堂噜噜噜 | 国产成人高清视频 | 国产三区四区 | 日韩精品在线观看视频 | 日本精品一区二区在线观看 | 日本精品一区二区三区四区 | 成人免费小视频 | 成人在线视频免费观看 | 一本一道久久a久久精品蜜桃 | 国产在线不卡视频 | 久国产视频 | 日韩在线一区二区三区 | 国产视频精品免费 | 精品国产乱码久久久久久88av | 中文字幕国产一区 | 亚洲一区久久久 | 中文字幕一区二区三区四区不卡 | 亚洲视屏 | 男女免费网站 | 在线播放亚洲 | 爱爱视频在线观看 | 精品免费 | 婷婷亚洲综合 | 99综合 | 波多野结衣精品 | 国产 日韩 欧美 中文 在线播放 | 看片国产 | 日韩在线一区二区三区 | 91亚洲欧美 | 成人在线不卡 | 天天天天天天天干 | 国产精品久久久久久久久久久久久 | 欧美一级免费 | 日本在线一区二区 | 欧美成人影院在线 | 99精品久久99久久久久 | 69电影网 | 国产福利91精品一区二区三区 |