本文介紹了如何在 Python 進程之間共享數據?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在使用多處理為我的 Python 應用程序創建一個子進程.我想在我的父進程和子進程之間共享數據.需要說明的是,我需要異步共享這個,也就是說子進程和父進程會在代碼運行期間更新數據.
I'm using multiprocessing to create a sub-process to my Python app. I would like to share data between my parent process and the child process. it's important to mention that I need to share this asynchronously, means that the child process and the parent process will update the data during the code running.
最好的方法是什么?
推薦答案
這是python文檔中的一個簡單示例 -
This is one simple example from python documentation -
from multiprocessing import Process, Queue
def f(q):
q.put([42, None, 'hello'])
if __name__ == '__main__':
q = Queue()
p = Process(target=f, args=(q,))
p.start()
print q.get() # prints "[42, None, 'hello']"
p.join()
你也可以使用管道,有關詳細信息,請參閱 - https://docs.python.org/2/library/multiprocessing.html
You can use pipe as well, Refer for more details - https://docs.python.org/2/library/multiprocessing.html
這篇關于如何在 Python 進程之間共享數據?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!