关于python:在Windows中复制fork()的最佳方法是什么?

关于python:在Windows中复制fork()的最佳方法是什么?

What's the best way to duplicate fork() in windows?

如何实现一些逻辑,使我能够使用Python在Windows上通过fork()系统调用重现Linux上的功能?

我专门尝试在SAPI Com组件上执行一个方法,同时在主线程中继续其他逻辑而不阻塞或等待。


使用可在任何地方使用的python多处理模块。

这是一篇IBM developerWords文章,显示了如何从os.fork()转换为多处理模块。


fork()实际上已经在Windows的Cygwin下被复制了,但是非常毛茸茸。

The fork call in Cygwin is particularly interesting because it does not map well on top of the Win32 API. This makes it very difficult to implement correctly.

有关此黑客的说明,请参见《 Cygwin用户指南》。


Eli的Threading示例将运行该线程,但在该行之后不执行任何工作。

我将研究处理模块和子过程模块。我认为我正在运行的com方法需要在另一个进程中,而不仅仅是在另一个线程中。


除了Greg指出的os模块中的流程管理代码外,您还应该看看线程模块:https://docs.python.org/library/threading.html

1
2
3
4
5
6
7
from threading import Thread

def separate_computations(x, y):
    print sum(x for i in range(y))  # really expensive multiplication

Thread(target=separate_compuations, args=[57, 83]).start()
print"I'm continuing while that other function runs in another thread!"

看看os模块中的流程管理功能。具有用于以多种不同方式(同步和异步)启动新进程的功能。

我还要注意Windows在其他系统上没有提供与fork()完全相同的功能。要在Windows上进行多处理,您将需要使用线程模块。


您可能还喜欢使用处理模块(http://pypi.python.org/pypi/processing)。它具有许多功能,可使用与线程模块相同的API编写并行系统。


可能是python的spawn()版本吗? http://en.wikipedia.org/wiki/Spawn_(operating_system)


推荐阅读