2008-08-22 44 views

回答

0

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

+0

這就是`多處理`這些天在Windows上做的事情。 https://docs.python.org/3.5/library/multiprocessing.html?highlight=spawn#contexts-and-start-methods – clacke 2016-09-13 13:06:12

3

查看os module中的進程管理功能。有許多功能可以通過許多不同的方式啓動新進程,包括同步和異步啓動。

我還應該注意到Windows不提供與其他系統上的fork()完全相同的功能。要在Windows上執行多處理,您需要使用threading模塊。

+8

`subprocess`和`multiprocessing`(由RJBrady建議)可能是更好的替代`os`和`線程`。 – jfs 2008-10-04 17:24:23

+1

`線程`不會在CPython中進行實際的多處理。 – clacke 2016-09-13 12:56:19

3

除了os模塊格雷格指出,在這個過程中管理代碼,你也應該看看線程模塊: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_compuations, args=[57, 83]).start() 
print "I'm continuing while that other function runs in another thread!" 
2

你可能還喜歡使用處理模塊(http://pypi.python.org/pypi/processing) 。它具有很多用於使用與線程模塊相同的API編寫並行系統的功能...

+1

從Python 2.6/3.0(2008年10月和12月)開始,`processing`就是`multiprocessing`的標準庫的一部分。 – clacke 2016-09-13 13:01:14

3

來自Eli的線程示例將運行線程,但不會執行該線之後的任何工作。

我打算查看處理模塊和子流程模塊。我認爲我運行的com方法需要在另一個進程中,而不是在另一個線程中。

+2

`multiprocessing`模塊是標準庫的一部分。 `subprocess`適合外部程序,``multiprocessing`適合python代碼。 – jfs 2008-10-04 17:21:19

10

fork()已有實際上在Windows中重複,在Cygwin下,但它很毛茸茸。

Cygwin中的fork調用特別有趣,因爲它在Win32 API上映射不好。這使得正確實施非常困難。

查看The Cygwin User's Guide瞭解這個黑客攻擊的描述。

相關問題