How to use the multiprocess.Process function in multiprocess

To help you get started, we’ve selected a few multiprocess 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 hballard / graphql-python-subscriptions / tests / test_subscription_transport.py View on Github external
def server_with_mocks(sub_mgr, schema, options_mocks):

    options, q = options_mocks
    app = create_app(sub_mgr, schema, options)

    process = multiprocess.Process(
        target=app_worker, kwargs={'app': app,
                                   'port': TEST_PORT})

    process.start()
    yield q
    process.terminate()
github uqfoundation / multiprocess / py2.6 / examples / benchmarks.py View on Github external
def test_pipespeed():
    c, d = processing.Pipe()
    cond = processing.Condition()
    elapsed = 0
    iterations = 1

    while elapsed < delta:
        iterations *= 2

        p = processing.Process(target=pipe_func, args=(d, cond, iterations))
        cond.acquire()
        p.start()
        cond.wait()
        cond.release()

        result = None
        t = _timer()

        while result != 'STOP':
            result = c.recv()

        elapsed = _timer() - t
        p.join()

    print iterations, 'objects passed through connection in',elapsed,'seconds'
    print 'average number/sec:', iterations/elapsed
github uqfoundation / multiprocess / py2.6 / examples / ex_synchronize.py View on Github external
def test_condition():
    cond = processing.Condition()

    p = processing.Process(target=condition_func, args=(cond,))
    print cond

    cond.acquire()
    print cond
    cond.acquire()
    print cond

    p.start()

    print 'main is waiting'
    cond.wait()
    print 'main has woken up'

    print cond
    cond.release()
    print cond
github uqfoundation / multiprocess / py3.2 / examples / benchmarks.py View on Github external
def test_pipespeed():
    c, d = processing.Pipe()
    cond = processing.Condition()
    elapsed = 0
    iterations = 1

    while elapsed < delta:
        iterations *= 2

        p = processing.Process(target=pipe_func, args=(d, cond, iterations))
        cond.acquire()
        p.start()
        cond.wait()
        cond.release()

        result = None
        t = _timer()

        while result != 'STOP':
            result = c.recv()

        elapsed = _timer() - t
        p.join()

    print(iterations, 'objects passed through connection in',elapsed,'seconds')
    print('average number/sec:', iterations/elapsed)
github uqfoundation / multiprocess / py2.7 / examples / ex_synchronize.py View on Github external
def test_sharedvalues():
    values = [
        ('i', 10),
        ('h', -2),
        ('d', 1.25)
        ]
    arrays = [
        ('i', range(100)),
        ('d', [0.25 * i for i in range(100)]),
        ('H', range(1000))
        ]

    shared_values = [processing.Value(id, v) for id, v in values]
    shared_arrays = [processing.Array(id, a) for id, a in arrays]

    p = processing.Process(
        target=sharedvalues_func,
        args=(values, arrays, shared_values, shared_arrays)
        )
    p.start()
    p.join()
    
    assert p.exitcode == 0
github uqfoundation / multiprocess / py3.2 / examples / benchmarks.py View on Github external
test_lockspeed(processing.Lock())
    print('\n\t######## testing processing.RLock\n')
    test_lockspeed(processing.RLock())
    print('\n\t######## testing lock managed by server process\n')
    test_lockspeed(manager.Lock())
    print('\n\t######## testing rlock managed by server process\n')
    test_lockspeed(manager.RLock())

    print()

    print('\n\t######## testing threading.Condition\n')
    test_conditionspeed(threading.Thread, threading.Condition())
    print('\n\t######## testing processing.Condition\n')
    test_conditionspeed(processing.Process, processing.Condition())
    print('\n\t######## testing condition managed by a server process\n')
    test_conditionspeed(processing.Process, manager.Condition())

    gc.enable()
github higlass / higlass-python / higlass / server.py View on Github external
# we're going to assign a uuid to each server process so that if
        # anything goes wrong, the variable referencing the process doesn't get
        # lost
        uuid = slugid.nice()
        if self.port is None:
            self.port = get_open_port()
        target = partial(
            self.app.run,
            threaded=True,
            debug=True,
            host=self.host,
            port=self.port,
            use_reloader=False,
        )
        self.processes[uuid] = mp.Process(target=target)
        self.processes[uuid].start()
        self.connected = False
        while not self.connected:
            try:
                url = "http://{}:{}/api/v1".format(self.host, self.port)
                r = requests.head(url)
                if r.ok:
                    self.connected = True
            except requests.ConnectionError:
                time.sleep(0.2)
github jacobkahn / reinforcement-learning-market-microstructure / util / agent.py View on Github external
- replay buffer
"""
if __name__ == "__main__":
	# define method params
	doubleQbackup = {
		'name': 'doubleQ'
	}
	samplingBackup = {
		'name': 'sampling'
	}
	replayBufferBackup = { 'name': 'replay buffer',
					'buff_size': 50,
					'replays': 5
	}
	# tables
	doubleQProcess = multiprocess.Process(target=dp_algo, args=("../data/10_GOOG.csv", 1000, 1000, 10, 10, 10, doubleQbackup, 100000))
	samplingProcess = multiprocess.Process(target=dp_algo, args=("../data/10_GOOG.csv", 1000, 1000, 10, 10, 10, samplingBackup, 100000))
	replayBufferProcess = multiprocess.Process(target=dp_algo, args=("../data/10_GOOG.csv", 1000, 1000, 10, 10, 10, replayBufferBackup, 100000))
	# start
	#doubleQProcess.start()
	samplingProcess.start()
	#replayBufferProcess.start()
github higlass / higlass-python / higlass / server.py View on Github external
disk_cache_dir=self.diskcache_directory,
                        lru_capacity=lru_capacity,
                    ),
                    directory,
                    foreground=False,
                    # allow_other=True
                )
            except RuntimeError as e:
                if str(e) != "1":
                    raise e

        proc1 = mp.Process(target=start_fuse, args=[self.http_directory, "http"])
        proc1.start()
        proc1.join()

        proc2 = mp.Process(target=start_fuse, args=[self.https_directory, "https"])
        proc2.start()
        proc2.join()
github BerkeleyAutomation / yumipy / tools / yumi_ipython.py View on Github external
from yumipy import *
from autolab_core import *

from time import sleep

import logging
import IPython
import numpy as np

YMC = YuMiConstants

from multiprocess import Process, Queue

class P(Process):

    def __init__(self, y):
        Process.__init__(self)
        self.y = y

    def run(self):
        #self.y = YuMiRobot()
        p = self.y.left.get_pose()
        print p
        self.y.reset_home()
        print 'finished'

if __name__ == '__main__':
    logging.getLogger().setLevel(logging.INFO)
    y = YuMiRobot()
    p = P(y)