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

发布于 2024-07-05 00:48:52 字数 142 浏览 8 评论 0原文

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

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

How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the fork() system call, using Python?

I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

十年九夏 2024-07-12 00:48:52

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

Possibly a version of spawn() for python? http://en.wikipedia.org/wiki/Spawn_(operating_system)

软的没边 2024-07-12 00:48:52

使用 python 多处理模块,它可以在任何地方工作。

以下是 IBM DeveloperWords 文章,展示了如何从 os. fork() 到多处理模块。

Use the python multiprocessing module which will work everywhere.

Here is a IBM developerWords article that shows how to convert from os.fork() to the multiprocessing module.

独闯女儿国 2024-07-12 00:48:52

fork() 事实上在 Windows 中被复制,位于 Cygwin,但它的毛茸茸的。

Cygwin 中的 fork 调用特别有趣,因为它不能很好地映射到 Win32 API 之上。 这使得正确实施变得非常困难。

有关以下说明,请参阅Cygwin 用户指南这个黑客。

fork() has in fact been duplicated in Windows, under Cygwin, but it's pretty hairy.

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.

See the The Cygwin User's Guide for a description of this hack.

离笑几人歌 2024-07-12 00:48:52

查看os 模块中的进程管理功能。 有多种不同方式(同步和异步)启动新进程的函数。

我还应该指出,Windows 不提供与其他系统上的 fork() 完全相同的功能。 要在 Windows 上进行多处理,您需要使用 threading 模块。

Have a look at the process management functions in the os module. There are function for starting new processes in many different ways, both synchronously and asynchronously.

I should note also that Windows doesn't provide functionality that is exactly like fork() on other systems. To do multiprocessing on Windows, you will need to use the threading module.

放低过去 2024-07-12 00:48:52

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

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

The Threading example from Eli will run the thread, but not do any of the work after that line.

I'm going to look into the processing module and the subprocess module. I think the com method I'm running needs to be in another process, not just in another thread.

我偏爱纯白色 2024-07-12 00:48:52

You might also like using the processing module (http://pypi.python.org/pypi/processing). It has lot's of functionality for writing parallel systems with the same API as the threading module...

强者自强 2024-07-12 00:48:52

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

    from threading import Thread
    
    def separate_computations(x, y):
        print sum(x for i in range(y))  # really expensive multiplication
    
    Thread(target=separate_computations, args=[57, 83]).start()

    print "I'm continuing while that other function runs in another thread!"

In addition to the process management code in the os module that Greg pointed out, you should also take a look at the threading module:
https://docs.python.org/library/threading.html

    from threading import Thread
    
    def separate_computations(x, y):
        print sum(x for i in range(y))  # really expensive multiplication
    
    Thread(target=separate_computations, args=[57, 83]).start()

    print "I'm continuing while that other function runs in another thread!"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文