How to use mitogen - 10 common examples

To help you get started, we’ve selected a few mitogen 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 dw / mitogen / tests / bench / throughput.py View on Github external
def run_test(router, fp, s, context):
    fp.seek(0, 2)
    size = fp.tell()
    print('Testing %s...' % (s,))
    context.call(prepare)
    t0 = mitogen.core.now()
    context.call(transfer, router.myself(), fp.name)
    t1 = mitogen.core.now()
    print('%s took %.2f ms to transfer %.2f MiB, %.2f MiB/s' % (
        s, 1000 * (t1 - t0), size / 1048576.0,
        (size / (t1 - t0) / 1048576.0),
    ))
github dw / mitogen / tests / bench / throughput.py View on Github external
def run_test(router, fp, s, context):
    fp.seek(0, 2)
    size = fp.tell()
    print('Testing %s...' % (s,))
    context.call(prepare)
    t0 = mitogen.core.now()
    context.call(transfer, router.myself(), fp.name)
    t1 = mitogen.core.now()
    print('%s took %.2f ms to transfer %.2f MiB, %.2f MiB/s' % (
        s, 1000 * (t1 - t0), size / 1048576.0,
        (size / (t1 - t0) / 1048576.0),
    ))
github dw / mitogen / tests / bench / throughput.py View on Github external
@mitogen.main()
def main(router):
    ansible_mitogen.affinity.policy.assign_muxprocess()

    bigfile = tempfile.NamedTemporaryFile()
    fill_with_random(bigfile, 1048576*512)

    file_service = mitogen.service.FileService(router)
    pool = mitogen.service.Pool(router, ())
    file_service.register(bigfile.name)
    pool.add(file_service)
    try:
        context = router.local()
        run_test(router, bigfile, 'local()', context)
        context.shutdown(wait=True)

        context = router.sudo()
github dw / mitogen / tests / bench / fork.py View on Github external
@mitogen.main()
def main(router):
    t0 = mitogen.core.now()
    for x in xrange(200):
        t = mitogen.core.now()
        ctx = router.fork()
        ctx.shutdown(wait=True)
    print '++', 1000 * ((mitogen.core.now() - t0) / (1.0+x))
github dw / mitogen / tests / testlib.py View on Github external
sock.settimeout(connect_timeout)
        try:
            sock.connect(addr)
        except socket.error:
            # Failed to connect. So wait then retry.
            time.sleep(sleep)
            continue

        if not pattern:
            # Success: We connected & there's no banner check to perform.
            sock.shutdown(socket.SHUTD_RDWR)
            sock.close()
            return

        sock.settimeout(receive_timeout)
        data = mitogen.core.b('')
        found = False
        while mitogen.core.now() < end:
            try:
                resp = sock.recv(1024)
            except socket.timeout:
                # Server stayed up, but had no data. Retry the recv().
                continue

            if not resp:
                # Server went away. Wait then retry the connection.
                time.sleep(sleep)
                break

            data += resp
            if re.search(mitogen.core.b(pattern), data):
                found = True
github dw / mitogen / tests / bench / latch_roundtrip.py View on Github external
out.put(None)


ready = mitogen.core.Latch()
l1 = mitogen.core.Latch()
l2 = mitogen.core.Latch()

t1 = threading.Thread(target=flip_flop, args=(ready, l1, l2))
t2 = threading.Thread(target=flip_flop, args=(ready, l2, l1))
t1.start()
t2.start()

ready.get()
ready.get()

t0 = mitogen.core.now()
l1.put(None)
t1.join()
t2.join()
print('++', int(1e6 * ((mitogen.core.now() - t0) / (1.0+X))), 'usec')
github dw / mitogen / tests / bench / large_messages.py View on Github external
def main(router):
    c = router.fork()

    n = 1048576 * 127
    s = ' ' * n
    print('bytes in %.2fMiB string...' % (n/1048576.0),)

    t0 = mitogen.core.now()
    for x in range(10):
        tt0 = mitogen.core.now()
        assert n == c.call(len, s)
        print('took %dms' % (1000 * (mitogen.core.now() - tt0),))
    t1 = mitogen.core.now()
    print('total %dms / %dms avg / %.2fMiB/sec' % (
        1000 * (t1 - t0),
        (1000 * (t1 - t0)) / (x + 1),
        ((n * (x + 1)) / (t1 - t0)) / 1048576.0,
    ))
github dw / mitogen / tests / bench / roundtrip.py View on Github external
def main(router):
    f = router.fork()
    f.call(do_nothing)
    t0 = mitogen.core.now()
    for x in xrange(20000):
        f.call(do_nothing)
    print('++', int(1e6 * ((mitogen.core.now() - t0) / (1.0+x))), 'usec')
github dw / mitogen / tests / bench / local.py View on Github external
def main(router):
    t0 = mitogen.core.now()
    for x in range(100):
        t = mitogen.core.now()
        f = router.local()# debug=True)
        tt = mitogen.core.now()
        print(x, 1000 * (tt - t))
    print('%.03f ms' % (1000 * (mitogen.core.now() - t0) / (1.0 + x)))
github dw / mitogen / tests / bench / roundtrip.py View on Github external
@mitogen.main()
def main(router):
    f = router.fork()
    f.call(do_nothing)
    t0 = mitogen.core.now()
    for x in xrange(20000):
        f.call(do_nothing)
    print('++', int(1e6 * ((mitogen.core.now() - t0) / (1.0+x))), 'usec')