def run_simulation(network_model, sim, parameters, input_queue, output_queue):
    """
    Build the model defined in the class `network_model`, with parameters
    `parameters`, and then consume tasks from `input_queue` until receiving the
    command 'STOP'.
    """
    print('Running simulation with %s' % sim.__name__)
    network = network_model(sim, parameters)
    print('Network constructed with %s.' % sim.__name__)
    for obj_name, attr, args, kwargs in iter(input_queue.get, 'STOP'):
        print('%s processing command %s.%s(%s, %s)' % (sim.__name__,
            obj_name, attr, args, kwargs))
        obj = eval(obj_name)
        result = getattr(obj, attr)(*args, **kwargs)
        output_queue.put(result)
    print('Simulation with %s complete' % sim.__name__)
