How to do adding to the list of Pool.map?

Hello

Not so long ago sat behind Python, impressive, but yet to come across a puzzling moments.
Prompt, please, the correct solution for this task.

Need to run multiple processes that add to the list of cards[] arbitrary number of records.

import time
import os
from multiprocessing import Process, Pool

def add_card(card):
 print('*** 1 ***' + str(card))
 pid = os.getpid()
 card.append( {'id': 7, 'descr': pid})
time.sleep(1)
 print('*** 2 ***' + str(card))
 return (card)

if __name__ == '__main__':
cards=[]
 cards.append( {'id': 1, 'descr': 'First'})
 cards.append( {'id': 2, 'descr': 'Second'})
 cards.append( {'id': 3, 'descr': 'Third'})
 cards.append( {'id': 4, 'descr': 'Fourth'})
 cards.append( {'id': 5, 'descr': 'Fifth'})
 cards.append( {'id': 6, 'descr': 'Sixth'})
 print('*** NEW ***' + str(cards))


#3 run of the process at the entrance give a list of three tuples (cards)

with Pool(3) as p:
 p.map(add_card, (cards,)*3 )

print('*** FIN ***' + str(cards))


The result:
*** NEW ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}]

*** 1 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}]

*** 2 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}, {'id': 7, 'descr': 15048}]

*** 1 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}]

*** 2 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}, {'id': 7, 'descr': 17432}]

*** 1 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}]

*** 2 ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}, {'id': 7, 'descr': 17732}]

*** FIN ***[{'id': 1, 'descr': 'First'}, {'id': 2, 'descr': 'Second'}, {'id': 3, 'descr': 'Third'}, {'id': 4, 'descr': 'Fourth'}, {'id': 5, 'descr': 'Fifth'}, {'id': 6, 'descr': The 'sixth'}]


And I would like to list cards in a body of running processes added a new record.
Invite the right idea plz
March 23rd 20 at 19:01
1 answer
March 23rd 20 at 19:03
with Pool(3) as p:
 result = p.map(add_card, (cards,)*3 )
print(result)

And def add_card to remove the prints
Formatting and output add_card to prescribe in any option, at the end of it and return in a function)

Find more questions by tags Python