0

My program creates two pools:

file_creator_pool initialized with filenum variable which is stored in global total_files to be accessible for all processes in the pool

#global
total_files = None

def init_creator_pool(filenum):
    global total_files
    total_files = filenum

filenum = multiprocessing.Manager().Value('i', 0) 
file_creator_pool = multiprocessing.Pool(MAX_PROCESSES, initializer=init_creator_pool, initargs=(filenum,))

Now I want total_files be accessible in ranamer_pool as well

file_renamer_pool = multiprocessing.Pool(MAX_PROCESSES)

Is it possible?

Thanks

Samuel
  • 3,631
  • 5
  • 37
  • 71
  • 1
    You can use the same technique you are already using. Your code seems a bit odd though: it's not clear why you are making a managed value and then passing it as well (the point of managed values is that `multiprocessing` sends them around automatically). See http://stackoverflow.com/a/17393879/1256452 and also http://stackoverflow.com/a/660468/1256452 – torek Jun 23 '16 at 06:49
  • @torek Thanks torek, but what do you mean "the same technique"? Do you mean that `filenum` should be visible for `file_renamer_pool` processes anyway? Now about the code, AFAIK it's the way to share share variable among processes in the pool when they're going to access it for writing. Do you mean just crate global managed `filenum` without passing it to Pool ctor? – Samuel Jun 23 '16 at 13:29
  • 1
    If you're changing `filenum` in each Process, yes, you do need something like this, at least on Windows. (I don't see anything writing new values into `filenum`, but that may just not be visible in your code snippet.) What I mean by "the same technique" is that you can pass `initializer=` and `initargs=`, yes (perhaps even using the very same function). – torek Jun 23 '16 at 18:07
  • @torek Thanks torek will try. Indeed, processes from `file_creator_pool` do change `filenum` so I have to aquire and release lock on it. This code snippet isn't presented here since I think it not relevant to actual question – Samuel Jun 26 '16 at 17:42

0 Answers0