Exemplo n.º 1
0
def initialize(n_parallel):
    """Initialize the worker pool.

    SIGINT is blocked for all processes created in parallel_sampler to avoid
    the creation of sleeping and zombie processes.

    If the user interrupts run_experiment, there's a chance some processes
    won't die due to a dead lock condition where one of the children in the
    parallel sampler exits without releasing a lock once after it catches
    SIGINT.

    Later the parent tries to acquire the same lock to proceed with his
    cleanup, but it remains sleeping waiting for the lock to be released.
    In the meantime, all the process in parallel sampler remain in the zombie
    state since the parent cannot proceed with their clean up.

    Parameters
    ----------
    n_parallel : int
        Number of workers to run in parallel.
    """

    try:
        signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGINT])
        singleton_pool.initialize(n_parallel)
        singleton_pool.run_each(_worker_init,
                                [(id, )
                                 for id in range(singleton_pool.n_parallel)])
    finally:
        signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGINT])
Exemplo n.º 2
0
def initialize(n_parallel):
    singleton_pool.initialize(n_parallel)
    singleton_pool.run_each(_worker_init,
                            [(id, )
                             for id in range(singleton_pool.n_parallel)])