How to use the multiprocessing.Event function in multiprocessing

To help you get started, we’ve selected a few multiprocessing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andymccurdy / redis-py / tests / test_multiprocessing.py View on Github external
A connection owned by a parent is unusable by a child if the parent
        (the owning process) closes the connection.
        """
        conn = Connection()
        conn.send_command('ping')
        assert conn.read_response() == b'PONG'

        def target(conn, ev):
            ev.wait()
            # the parent closed the connection. because it also created the
            # connection, the connection is shutdown and the child
            # cannot use it.
            with pytest.raises(ConnectionError):
                conn.send_command('ping')

        ev = multiprocessing.Event()
        proc = multiprocessing.Process(target=target, args=(conn, ev))
        proc.start()

        conn.disconnect()
        ev.set()

        proc.join(3)
        assert proc.exitcode == 0
github Ericsson / codechecker / tests / functional / package_test / __init__.py View on Github external
# sys.path modification needed so nosetests can load the test_utils package.
sys.path.append(os.path.abspath(__REPO_ROOT))

# Because of the nature of the python-env loading of nosetests, we need to
# add the codechecker_gen package to the pythonpath here, so it is available
# for the actual test cases.
__PKG_ROOT = os.path.abspath(os.environ['CC_PACKAGE'])

__LAYOUT_FILE_PATH = os.path.join(__PKG_ROOT, 'config', 'package_layout.json')
with open(__LAYOUT_FILE_PATH) as layout_file:
    __PACKAGE_LAYOUT = json.load(layout_file)
sys.path.append(os.path.join(
    __PKG_ROOT, __PACKAGE_LAYOUT['static']['codechecker_gen']))

# Stopping event for CodeChecker server.
__STOP_SERVER = multiprocessing.Event()


def get_free_port():
    '''Get a free port from the OS.'''

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 0))
    free_port = s.getsockname()[1]
    s.close()

    return free_port


def _wait_for_postgres_shutdown(workspace):
    """
    Wait for PostgreSQL to shut down.
github MatthieuDartiailh / HQCMeas / tests / tasks / util_tasks / test_load_tasks.py View on Github external
def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LoadArrayTask(task_name='Test')
        self.task.interface = CSVLoadInterface()
        self.task.folder = FOLDER_PATH
        self.task.filename = 'fake.dat'
        self.root.children_task.append(self.task)
github programa-stic / Marvin-dynamic-Analyzer / client / VMClient.py View on Github external
def start_component_and_wait_for_initialization(self, target):
        signal_init = multiprocessing.Event()
        signal_close = multiprocessing.Event()
        process = multiprocessing.Process(target=target, args=(self.error_queue, signal_init, signal_close))
        process.start()
        # wait for initialization
        signal_init.wait()
        return (process, signal_close)
github armandmcqueen / tensorpack-mask-rcnn / tensorpack / callbacks / prof.py View on Github external
def _before_train(self):
        assert gpu_available_in_session(), "[GPUUtilizationTracker] needs GPU!"
        self._evt = mp.Event()
        self._stop_evt = mp.Event()
        self._queue = mp.Queue()
        self._proc = mp.Process(target=self.worker, args=(
            self._evt, self._queue, self._stop_evt))
        ensure_proc_terminate(self._proc)
        start_proc_mask_signal(self._proc)
github macanv / BERT-BiLSTM-CRF-NER / bert_base / server / __init__.py View on Github external
def __init__(self, args, front_sink_addr):
        super().__init__()
        self.port = args.port_out
        self.exit_flag = multiprocessing.Event()
        self.logger = set_logger(colored('SINK', 'green'), args.verbose)
        self.front_sink_addr = front_sink_addr
        self.verbose = args.verbose
        self.args = args
github lindemann09 / pyForceDAQ / forceDAQ / sensor.py View on Github external
self._write_queue_after_pause = write_queue_after_pause
        self._event_polling = Event()
        self.event_bias_is_available = Event()
        self.daemon = True

        self._last_Fx = sharedctypes.RawValue(ct.c_float)
        self._last_Fy = sharedctypes.RawValue(ct.c_float)
        self._last_Fz = sharedctypes.RawValue(ct.c_float)
        self._last_Tx = sharedctypes.RawValue(ct.c_float)
        self._last_Ty = sharedctypes.RawValue(ct.c_float)
        self._last_Tz = sharedctypes.RawValue(ct.c_float)
        self._buffer_size = sharedctypes.RawValue(ct.c_uint64)
        self._sample_cnt = sharedctypes.Value(ct.c_uint64)

        self._event_stop_request = Event()
        self._determine_bias_flag = Event()

        self._bias_n_samples = 200
        atexit.register(self.stop)
github celery / celery / celery / concurrency / processes / pool.py View on Github external
def _create_worker_process(self):
        sentinel = Event()
        w = self.Process(
            force_execv=self._force_execv,
            target=worker,
            args=(self._inqueue, self._outqueue,
                    self._initializer, self._initargs,
                    self._maxtasksperchild,
                    sentinel),
            )
        self._pool.append(w)
        w.name = w.name.replace('Process', 'PoolWorker')
        w.daemon = True
        w.start()
        self._poolctrl[w.pid] = sentinel
        return w
github tilezen / tilepacks / tilepack / builder.py View on Github external
import argparse
import csv
import gzip
import mercantile
import multiprocessing
import os
import random
import requests
import signal
import tilepack.outputter
import time
import traceback

shutdown_event = multiprocessing.Event()
verbose = False

class ShutdownException(Exception):
    pass

sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=200)
sess.mount('https://', adapter)

# def fetch_tile(x, y, z, type, layer, tile_size, tile_format, api_key):
def fetch_tile(format_args):
    sleep_time = 0.5 * random.uniform(1.0, 1.7)
    response_info = []

    if shutdown_event.is_set():
        raise ShutdownException("Shutdown event set")
github renskiy / fabricio / fabricio / decorators.py View on Github external
lock = last_task.get_lock()
        if lock.acquire(block):
            try:
                current_task = get_current_task_id()
                if current_task != last_task.raw:
                    last_task.raw = current_task
                    results[current_task] = result = func(*args, **kwargs)
                    return result
                return results.get(current_task, default)
            finally:
                executed.set()
                lock.release()

    last_task = multiprocessing.Array(ctypes.c_char, hashlib.md5().digest_size)
    results = multiprocessing.Manager().dict()
    executed = multiprocessing.Event()

    _func.has_result = has_result
    _func.reset = reset
    _func.wait = wait
    _func.set = set_result

    _func.wrapped = func  # compatibility with Fabric tasks

    return _func