Python Forum
Updating variables in Multi-processing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating variables in Multi-processing
#1
Hi guys,

I'm struggling to get the correct code configuration to update an integer variable across multi-process processes!

My code in brief is below:

import multiprocessing
from multiprocessing import Value

error_value = Value('i',0)  #assign as integer type

def get_data(url):
    try:
        ...code doing some stuff here

    except ValueError as e:
       #if error thrown up simply count it
        error_value.acquire()
        error_value.value += 1
        error_value.release()
        pass 


if __name__ == '__main__':

# ---- Perform multi-processing 
    p = multiprocessing.Pool(6)
    results = p.map(get_data,'argslist')
    p.close()
    p.join()

    print(str(error_value.value))
So in the first instance I just want to count the number of errors thrown up in the function.

The output in the final print statement is zero but I know this not to be the case.

Any ideas please?
Reply


Messages In This Thread
Updating variables in Multi-processing - by WiPi - Feb-09-2021, 01:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strategy on updating edits back to data table and object variables hammer 0 1,215 Dec-11-2021, 02:58 PM
Last Post: hammer
  Multi-processing to communicate with microcontrollers Khoily 1 2,538 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,872 Sep-12-2018, 01:08 PM
Last Post: volcano63
  multi-processing dR_Garuby 1 2,678 Mar-24-2018, 05:59 PM
Last Post: woooee
  How does multi-processing in python increase the execution time? kadsank 0 2,349 Jan-15-2018, 01:15 PM
Last Post: kadsank
  Running Class methods in a loop and updating variables. ujjwalrathod007 3 6,426 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