Python Forum
multiprocess passing multiple arguments double asterisk
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiprocess passing multiple arguments double asterisk
#1
import multiprocessing as mp

def bar(**kwargs):
   for a in kwargs:
      print a,kwargs[a]

arguments={'name':'Joe','age':20}
p=mp.Pool(processes=4)
p.map(bar,**arguments)
p.close()
p.join()
Errors:

Traceback (most recent call last):
  File "post.py", line 9, in <module>
    p.map(bar,**arguments)
TypeError: map() got an unexpected keyword argument 'age'

How do I pass the dictionary arguments?

Thank you,
Reply
#2
just don't pass an argument.  with multiprocessing it forks whole process copies that inherit all the virtual memory.  so each subprocess will have its own copy of all the data the parent had.  if you need to pass data the other way, from child to parent, learn about pipes and files.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 401 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Passing writable arguments to functions. Assembler 11 977 Jan-15-2024, 11:32 PM
Last Post: sgrey
  Whys is asterisk and random variable necessary in these functions? rrowhe4d 5 1,523 Aug-05-2022, 07:53 AM
Last Post: Gribouillis
  Passing string functions as arguments Clunk_Head 3 1,257 Jun-15-2022, 06:00 AM
Last Post: Gribouillis
  multiprocess hang when certain number is used in the program esphi 7 3,204 Nov-06-2020, 03:49 PM
Last Post: esphi
  How to pass multiple arguments into function Mekala 4 2,458 Jul-11-2020, 07:03 AM
Last Post: Mekala
  redirect url_for passing arguments with the url Leon79 1 1,655 Jul-09-2020, 05:20 PM
Last Post: Leon79
  passing-arguments-from-one-script-to-another jacklee26 7 3,261 Apr-21-2020, 03:55 PM
Last Post: deanhystad
  Help removing asterisk item in a nested list. bmcguire 3 2,606 Apr-06-2020, 02:35 PM
Last Post: snippsat
  prometheus in multiprocess code georgelza 4 3,989 Jan-21-2020, 05:13 PM
Last Post: georgelza

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020