在Windows上使用Python的os.fork()有什么等效功能?

在Windows上使用Python的os.fork()有什么等效功能?

问题描述:

此代码在Mac/Linux上运行良好,但在Windows上却无法运行.

This code works well in Mac/Linux, but not in Windows.


import mmap
import os

map = mmap.mmap(-1, 13)
map.write("Hello world!")

pid = os.fork()

if pid == 0: # In a child process
    print 'child'
    map.seek(0)
    print map.readline()

    map.close()
else:
    print 'parent'

  • Windows上os.fork()的等效功能是什么?

取决于您的用例以及是否可以使用python 2.6,您也许可以使用

Depending on your use case and whether you can use python 2.6 or not, you might be able to use the multiprocessing module.