Skip to main content

get_shared_dict_value

Descripción

Obtener el valor de una clave en el diccionario interno compartido. Esta función es utilizada por todos los procesos paralelos.

Parámetros

Nombre Tipo Requerido Descripción
key str Si La clave en el diccionario compartido

Return 

Tipo
None

Versión

  • 1.0.0

Ejemplo

import pandoraPlugintools as pt

# Define a function to be executed by parallel processes
def process_data(item):
    # Process the data and get the value from the shared dictionary
    result = item * 2
    value = pt.get_shared_dict_value(key=str(item))
    print(f"Item: {item}, Processed Value: {result}, Shared Value: {value}")

# List of items to process
data_list = [1, 2, 3, 4, 5]

# Create a shared dictionary and lock for synchronization
shared_dict = multiprocessing.Manager().dict()
shared_dict_lock = multiprocessing.Manager().Lock()

# Set the shared dictionary and lock in the module
pt._SHARED_DICT = shared_dict
pt._SHARED_DICT_LOCK = shared_dict_lock

# Number of parallel processes to use
num_processes = 2

# Run the function for each item using parallel processes
success = pt.run_parallel(num_processes=num_processes, function=process_data, data_list=data_list, print_errors=True)

if success:
    print("All processes executed successfully.")
else:
    print("Errors occurred during process execution.")