1
我有一個異步函數被調用是這樣的:在Python中阻塞子進程函數?
from multiprocessing import Process
def my_function(arg1, arg2):
print 'Long process begins'
p = Process(target=my_function, args=(arg1, arg2,)).start()
我怎樣才能讓這個攔截?我需要在運行腳本的其餘部分之前完成該過程。
不要使用多進程。只需在腳本中調用'my_function'即可。它會「阻止」。 –
我需要將它作爲一個單獨的進程調用,因爲它與PyQt對象交互,這些對象會像瘋狂一樣泄漏內存。一旦子進程完成,內存就被釋放。 – nathancahill
如果你想有這個函數的返回值和錯誤處理,你可以使用[processify裝飾器](https://gist.github.com/2311116) – schlamar