看板 Python 關於我們 聯絡資訊
各位大大好: 最近小弟想學習多進程的使用方式,但看了很多網路上的範例 我發現我的電腦總是無法顯示加入多進程的函數本身print的內容 例如: #-*- coding:utf-8 -*- from multiprocessing import Process import os def run_proc(name): print 'Run child process %s (%s)...' % (name, os.getpid()) if __name__=='__main__': print 'Parent process %s.' % os.getpid() p = Process(target=run_proc, args=('test',)) print 'Process will start.' p.start() p.join() print 'Process end.' 上述的程式碼,教學文章表示執行後應該顯示 Parent process XXX. Process will start. Run child process test (929)... Process end. 但我在執行後,會無法出現函數中的Run child process test 這行 僅會顯示三行,這是為什麼呢? 是否有大大能提點一下...感激! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.32.193 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1491408475.A.460.html
zerof: 看來跟 #1OtHdIfO 是同樣問題.... 不是 code 的問題 04/06 00:17
leoricee: 所以是執行環境造成的嗎…怪怪 04/06 09:31
doun: 恩跟我遇到的問題一樣,我也還沒找到答案 04/06 09:47
leoricee: 剛試了一下,發現在IDLE環境下確實無法顯示,但在 04/06 10:16
leoricee: 命令提示列下執行就可以正常顯示了耶@@ 04/06 10:17
KSJ: https://goo.gl/qJd0UZ 供參考 04/06 12:24
leoricee: 明白了,謝謝KSJ大大解惑! 04/06 14:18
doun: 所以是表示在idle環境執行下都只會是單核運作,所以無法運 04/06 19:55
doun: 行多核運算嗎? 04/06 19:55
os653: 你試試看把 print 改成開隨機檔名的空白檔案,我猜會成功 04/06 20:19
os653: IDLE是個很奇葩的東西,用socket連接,效率低又易有怪問題 04/06 20:21