Python fork(): passing data from child to parent

后端 未结 1 1806
忘掉有多难
忘掉有多难 2021-02-14 17:09

I have a main Python process, and a bunch or workers created by the main process using os.fork().

I need to pass large and fairly involved data structures from the worke

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-14 18:00

    multiprocessing's queue implementation works.

    q = multiprocessing.Queue()
    if (os.fork() == 0):
        print(q.get())
    else:
        q.put(5)
    # outputs: 5
    

    0 讨论(0)
提交回复
热议问题