I am new to Python Multiprocessing. I am deploying my Python code in WSGI Gunicorn Multiprocessing environment. My requirement is, updated value of shared variable by one process needs to be picked up by another process. But I can see though one process is updating the value from 0 to 1 but still other process is not picking up the updated value 1, it is taking old value 0.
I have gone through some of the solution on internet but not able to solve this. Request you to help.
Note: As per my code logic, once lifecycle() method execution gets completed then only get_lifecycle() method will be called. (full code I can't paste due to some restrictions)
import os
from multiprocessing import Value
... some other imports
data = Value('i', 0)
class ResourceDriverHandler:
def lifecycle(self , driver_files): (called by a process - say, process 7)
try:
logger.info(f'checkpoint1 os.getpid() :{os.getpid()}')
logger.info('checkpoint1 data.value : %s : ', data.value)
.... some other code
driver.operation(driver_files)
.... some other code
except DriverConfigError as e:
logger.info(f'checkpoint2 os.getpid() :{os.getpid()}')
data.value += 1
logger.info('checkpoint2 data.value : %s : ', data.value)
def get_lifecycle(self): (called by another different process - say, process 5, once lifecycle() method execution is over)
logger.info(f'checkpoint3 os.getpid() :{os.getpid()}')
logger.info('checkpoint3 data.value : %s : ', data.value)
.... some other code
Gunicorn WSGI server Logs:
checkpoint1 os.getpid() : 7
checkpoint1 data.value : 0
checkpoint2 os.getpid() : 7
checkpoint2 data.value : 1
checkpoint3 os.getpid() : 5
checkpoint3 data.value : 0 (I was expecting 1 as already data.value is changed from 0 to 1 by another process)