跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • PY 在 Windows 下 Fork 之后在子进程执行一些操作要怎么做?
未分類
23 10 月 2020

PY 在 Windows 下 Fork 之后在子进程执行一些操作要怎么做?

PY 在 Windows 下 Fork 之后在子进程执行一些操作要怎么做?

資深大佬 : xzpjerry731 7

下面这段代码在 Unix 平台可以输出

(<function hook at 0x7fb4700730e0>,) func 

但是在 Windows 上就只打印 func 了,搜了一圈下来没有看到解决方法,故来求助。

import multiprocessing.util   def hook(*args):     print (args)   def func():     print ('func')    multiprocessing.util.register_after_fork(hook, hook) p = multiprocessing.Process(target=func) p.start() 

大佬有話說 (2)

  • 資深大佬 : iConnect

    Windows 没有这个机制,所以和 Linux 表现出差异。

  • 主 資深大佬 : xzpjerry731

    我试了下,这样就可以了

    ···
    import multiprocessing.util

    def hook(*args):
    print (args)

    def func():
    print (‘func’)

    multiprocessing.util.register_after_fork(hook, hook)
    if __name__ == ‘__main__’:
    p = multiprocessing.Process(target=func)
    p.start()
    ···

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具