D
D
Danila Rumyantsev2022-04-20 21:35:29
Python
Danila Rumyantsev, 2022-04-20 21:35:29

How to extract data from a child process?

As a result, I get 4 lists that need to be combined into 1, I tried queue, but it didn’t work, how can this be implemented?

spoiler
f __name__ == '__main__':
    print(len(m_id))
    cpus = multiprocessing.cpu_count()
    if length % cpus == 0:
        pass
    q_1 = multiprocessing.Queue()

    proc_1 = Process(target=get_mes, args=(m_id[0:length//4],q_1))#m_id[0:length//2

    proc_2 = Process(target=get_mes, args=(m_id[(length // 4)*2:(length // 4)*3],q_1))

    proc_3 = Process(target=get_mes, args=(m_id[(length // 4)*3:(length // 4)*4],q_1))
    proc_2.start()
    print('2')
    proc_3.start()
    print('3')
    proc_1.start()
    print('1')
    pr_1 = get_mes(m_id[length//2:(length//2)*2],0)
    pr_2 = q_1.get()
    pr_3 = q_1.get()
    pr_4 = q_1.get()
    all_mes = pr_1+pr_2+pr_3+pr_4
    print(len(all_mes))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-04-20
@Bubunduc

Try using Pool.map().
An example of its use is literally at the very beginning of the official documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question