2010-11-02 10 views
3

在並行Python中,爲什麼需要將所傳遞的函數以及該作業提交調用中的變量和名稱空間所需的任何模塊進行封裝 - 保留模塊級別「全局」變量的必要性如何? (如果這一切是怎麼回事)爲什麼並行Python的工作方式?

提交功能:

submit(self, func, args=(), depfuncs=(), modules=(), callback=None, callbackargs=(),group='default', globals=None) 
    Submits function to the execution queue 

    func - function to be executed 
    args - tuple with arguments of the 'func' 
    depfuncs - tuple with functions which might be called from 'func' 
    modules - tuple with module names to import 
    callback - callback function which will be called with argument 
     list equal to callbackargs+(result,) 
     as soon as calculation is done 
    callbackargs - additional arguments for callback function 
    group - job group, is used when wait(group) is called to wait for 
    jobs in a given group to finish 
    globals - dictionary from which all modules, functions and classes 
    will be imported, for instance: globals=globals() 

回答

3

pp工作方式是這樣,原因是它使Python解釋器爲每個工人,這是完全的一個新實例獨立於之前或之後運行的任何事物。這可確保沒有意外的副作用,例如__future__導入在工作進程中處於活動狀態。問題在於,它讓事情變得更加複雜,無法得到正確的結果,以我的經驗pp,並不是特別健壯。 pp確實試圖讓事情對用戶來說更容易些,但似乎引入了更多的問題,而不是解決它的努力。

如果我從一開始就編寫專門用於集羣的代碼,我可能會最終使用pp,但我發現使現有代碼適應pp是一場噩夢。

相關問題