Python Forum
Updating variables in Multi-processing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating variables in Multi-processing
#11
I think that's because you're trying to access the value within the Manager, after the manager's been cleaned up from the with block. Try this:
if __name__ == '__main__':
    with multiprocessing.Manager() as manager:
        with multiprocessing.Pool(6) as p:
            error_value = manager.Value('i', 0)
            args = itertools.product(input_list, [error_value])
            results = p.map(get_data, args)
 
        for result in results:
              ...
        print("Total errors:", error_value.value)
Reply
#12
(Feb-12-2021, 04:28 PM)nilamo Wrote: I think that's because you're trying to access the value within the Manager, after the manager's been cleaned up from the with block. Try this:
if __name__ == '__main__':
    with multiprocessing.Manager() as manager:
        with multiprocessing.Pool(6) as p:
            error_value = manager.Value('i', 0)
            args = itertools.product(input_list, [error_value])
            results = p.map(get_data, args)
 
        for result in results:
              ...
        print("Total errors:", error_value.value)


I ended up putting the print statement immediately after the results = p.map(get_data, args) just to be sure and it worked!!

What a difference a small change makes! LOL

Thanks again for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strategy on updating edits back to data table and object variables hammer 0 1,199 Dec-11-2021, 02:58 PM
Last Post: hammer
  Multi-processing to communicate with microcontrollers Khoily 1 2,514 Mar-01-2019, 08:57 PM
Last Post: DeaD_EyE
  Multi-processing - problem with running multiple *.py files at the same time Antonio 5 3,806 Sep-12-2018, 01:08 PM
Last Post: volcano63
  multi-processing dR_Garuby 1 2,662 Mar-24-2018, 05:59 PM
Last Post: woooee
  How does multi-processing in python increase the execution time? kadsank 0 2,321 Jan-15-2018, 01:15 PM
Last Post: kadsank
  Running Class methods in a loop and updating variables. ujjwalrathod007 3 6,376 Oct-05-2016, 07:11 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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