Example #1
0
def maker():
    for x in xrange(500000):
        d.dispatch(x)
        if x % 10000 == 0:
            sleep()
            log.info("values: {0}", r)
    quickstop()
 def l():
     t = time()
     sleep(0.3)
     delt = time() - t
     print delt
     WVPASS(delt > 0.275 and delt < 0.325)
     quickstop()
Example #3
0
def maker():
    for x in xrange(500000):
        d.dispatch(x)
        if x % 10000 == 0:
            sleep()
            log.info("values: {0}", r)
    quickstop()
 def l():
     t = time()
     sleep(0.05)
     WVPASS(v[0] == 2)
     sleep(0.1)
     WVPASS(v[0] == 4)
     quickstop()
 def l():
     sleep(0.05)
     cur = v[0]
     sleep()
     now = v[0]
     WVPASS(now == cur + 1)
     quickstop()
    def p():
        for x in xrange(c):
            q.put(x)
        sleep(1)
        WVPASS(done[0] == 1)

        quickstop()
    def p():
        for x in xrange(c):
            q.put(x)
        sleep(1)
        WVPASS(done[0] == 1)

        quickstop()
Example #8
0
 def parent():
     COUNT = 10000
     v = [0]
     for x in xrange(COUNT):
         fork(tottering_child, v)
     sleep(8)  # long enough on core 2-era
     WVPASS(v[0] == COUNT)
     quickstop()
Example #9
0
def client():
    with DieselNitroSocket(connect=loc) as sock:
        for x in xrange(100000):
            sock.send(NitroFrame("Hello, dude!"))
            m = sock.recv()
            assert m.data == "you said: Hello, dude!"

        quickstop()
Example #10
0
 def parent():
     COUNT = 10000
     v = [0]
     for x in xrange(COUNT):
         fork(tottering_child, v)
     sleep(8) # long enough on core 2-era
     WVPASS(v[0] == COUNT)
     quickstop()
Example #11
0
def client():
    with DieselNitroSocket(connect=loc) as sock:
        for x in xrange(100000):
            sock.send(NitroFrame("Hello, dude!"))
            m = sock.recv()
            assert m.data == "you said: Hello, dude!"

        quickstop()
Example #12
0
def end_the_app_when_my_parent_dies():
    try:
        while True:
            print "child: weeee!"
            sleep(1)
    except ParentDiedException:
        print "child: ack, woe is me, I'm an orphan.  goodbye cruel world"
        quickstop()
Example #13
0
def end_the_app_when_my_parent_dies():
    try:
        while True:
            print "child: weeee!"
            sleep(1)
    except ParentDiedException:
        print "child: ack, woe is me, I'm an orphan.  goodbye cruel world"
        quickstop()
Example #14
0
def do_echos():
    client = EchoClient('localhost', 8000)
    t = time.time()
    for x in xrange(5000):
        msg = "hello, world #%s!" % x
        echo_result = client.echo(msg)
        assert echo_result.strip() == "you said: %s" % msg
    log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()
Example #15
0
def do_echos():
    client = EchoClient('localhost', 8000)
    t = time.time()
    for x in xrange(5000):
        msg = "hello, world #%s!" % x
        echo_result = client.echo(msg)
        assert echo_result.strip() == "you said: %s" % msg
    log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()
Example #16
0
def do_echos():
    with EchoClient('localhost', 8000, ssl_ctx=SSL.Context(SSL.TLSv1_METHOD)) as client:
        t = time.time()
        for x in xrange(5000):
            msg = "hello, world #%s!" % x
            echo_result = client.echo(msg)
            assert echo_result.strip() == "you said: %s" % msg
        log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()
Example #17
0
def dependent_child():
    try:
        sleep(50)
    except ParentDiedException:
        got_exception = 1
    else:
        got_exception = 0
    WVPASS(got_exception)
    quickstop()
Example #18
0
def dependent_child():
    try:
        sleep(50)
    except ParentDiedException:
        got_exception = 1
    else:
        got_exception = 0
    WVPASS(got_exception)
    quickstop()
Example #19
0
def handle_messages():
    insock = DieselZMQSocket(zctx.socket(zmq.DEALER), bind="inproc://foo")

    for x in xrange(500000):
        msg = insock.recv()
        assert msg == "yo dawg %s" % x
    delt = time.time() - t
    print "500000 messages in %ss (%.1f/s)" % (delt, 500000.0 / delt)
    quickstop()
Example #20
0
    def p():
        for x in xrange(c):
            q.put(x)
        sleep(1)
        print s1, s2
        WVPASS(s1[0] < c)
        WVPASS(s2[0] < c)
        WVPASS(s1[0] + s2[0] == c)

        quickstop()
Example #21
0
def sieged():
    t = time.time()
    while True:
        n = wait('bam')
        if n % 10000 == 0:
            log.info(str(n))
            if n == 50000:
                delt = time.time() - t
                log.debug("50,000 messages in {0:.3f}s {1:.1f}/s)", delt, 50000 / delt)
                quickstop()
Example #22
0
def starter():
    print "Ready..."
    sleep(1)
    print "Set..."
    sleep(1)
    print " ~~~~~~~~~ BANG ~~~~~~~~~ "
    pistol.set()
    sleep(1)
    print " ~~~~~~~~~ RACE OVER ~~~~~~~~~ "
    quickstop()
Example #23
0
 def f():
     sleep(0.05)
     fire("boom!")
     sleep(0.05)
     WVPASS(v[0] == 2)
     sleep(0.05)
     fire("boom!")
     sleep(0.05)
     WVPASS(v[0] == 4)
     quickstop()
    def p():
        for x in xrange(c):
            q.put(x)
        sleep(1)
        print s1, s2
        WVPASS(s1[0] < c)
        WVPASS(s2[0] < c)
        WVPASS(s1[0] + s2[0] == c)

        quickstop()
Example #25
0
def starter():
    print "Ready..."
    sleep(1)
    print "Set..."
    sleep(1)
    print " ~~~~~~~~~ BANG ~~~~~~~~~ "
    pistol.set()
    sleep(1)
    print " ~~~~~~~~~ RACE OVER ~~~~~~~~~ "
    quickstop()
Example #26
0
def do_echos():
    with EchoClient('localhost', 8000,
                    ssl_ctx=SSL.Context(SSL.TLSv1_METHOD)) as client:
        t = time.time()
        for x in xrange(5000):
            msg = "hello, world #%s!" % x
            echo_result = client.echo(msg)
            assert echo_result.strip() == "you said: %s" % msg
        log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()
Example #27
0
def interact_python():
    """Runs an interactive interpreter; halts the diesel app when finished."""
    globals_ = globals()
    env = {
        '__builtins__': globals_['__builtins__'],
        '__doc__': globals_['__doc__'],
        '__name__': globals_['__name__'],
        'diesel': diesel,
    }
    code.interact(None, None, env)
    diesel.quickstop()
Example #28
0
def main():
    diesel.fork(track_cpu_stats)
    actor_pairs = int(sys.argv[1])
    done = Countdown(actor_pairs)
    for i in xrange(actor_pairs):
        pair(done)
    start = time.time()
    done.wait()
    print "done in %.2f secs" % (time.time() - start)
    diesel.sleep(1)
    diesel.quickstop()
Example #29
0
def main():
    diesel.fork(track_cpu_stats)
    actor_pairs = int(sys.argv[1])
    done = Countdown(actor_pairs)
    for i in xrange(actor_pairs):
        pair(done)
    start = time.time()
    done.wait()
    print "done in %.2f secs" % (time.time() - start)
    diesel.sleep(1)
    diesel.quickstop()
Example #30
0
def interact_python():
    """Runs an interactive interpreter; halts the diesel app when finished."""
    globals_ = globals()
    env = {
        '__builtins__':globals_['__builtins__'],
        '__doc__':globals_['__doc__'],
        '__name__':globals_['__name__'],
        'diesel':diesel,
    }
    code.interact(None, None, env)
    diesel.quickstop()
Example #31
0
def sieged():
    t = time.time()
    while True:
        n = wait('bam')
        if n % 10000 == 0:
            log.info(str(n))
            if n == 50000:
                delt = time.time() - t
                log.debug("50,000 messages in {0:.3f}s {1:.1f}/s)", delt,
                          50000 / delt)
                quickstop()
Example #32
0
def main():
    client = RedisClient('localhost', 6379)
    client.delete(key)
    client.set(incr_key, 0)

    for _ in xrange(500):
        fork(take_lock)
        if random.random() > 0.1:
            sleep(random.random() / 10)
    sleep(2)
    assert counter == int(client.get(incr_key)), 'Incr failed!'
    quickstop()
Example #33
0
def main():
    client = RedisClient('localhost', 6379)
    client.delete(key)
    client.set(incr_key, 0)

    for _ in xrange(500):
        fork(take_lock)
        if random.random() > 0.1:
            sleep(random.random() / 10)
    sleep(2)
    assert counter == int(client.get(incr_key)), 'Incr failed!'
    quickstop()
Example #34
0
def get_messages():
    outsock = DieselZMQSocket(zctx.socket(zmq.DEALER), bind="tcp://127.0.0.1:5000")

    for x in xrange(1000):
        t, m = first(sleep=1.0, waits=[outsock])

        if t == 'sleep':
            print "sleep timeout!"
        else:
            print "zmq:", m

    quickstop()
Example #35
0
def get_messages():
    outsock = DieselZMQSocket(zctx.socket(zmq.DEALER),
                              bind="tcp://127.0.0.1:5000")

    for x in xrange(1000):
        t, m = first(sleep=1.0, waits=[outsock])

        if t == 'sleep':
            print "sleep timeout!"
        else:
            print "zmq:", m

    quickstop()
Example #36
0
def get_messages():
    outsock = DieselZMQSocket(zctx.socket(zmq.DEALER), bind="tcp://127.0.0.1:5000")

    t = time.time()
    for x in xrange(500000):
        msg = outsock.recv()
        assert msg == "yo dawg %s" % x
        if x % 1000 == 0:
            sleep()

    delt = time.time() - t
    print "500000 messages in %ss (%.1f/s)" % (delt, 500000.0 / delt)
    quickstop()
Example #37
0
def get_messages():
    outsock = DieselZMQSocket(zctx.socket(zmq.DEALER),
                              bind="tcp://127.0.0.1:5000")

    t = time.time()
    for x in xrange(500000):
        msg = outsock.recv()
        assert msg == "yo dawg %s" % x
        if x % 1000 == 0:
            sleep()

    delt = time.time() - t
    print "500000 messages in %ss (%.1f/s)" % (delt, 500000.0 / delt)
    quickstop()
Example #38
0
def main():
    start = time.time()

    for i in xrange(NUM_ITEMS):
        q.put('item %d' % i)
    for i in xrange(NUM_WORKERS):
        q.put(shutdown)

    for i in xrange(NUM_WORKERS):
        diesel.fork_child(worker)
    for i in xrange(NUM_WORKERS):
        dones.get()

    print 'all workers done in %.2f secs' % (time.time() - start)
    diesel.quickstop()
Example #39
0
def main():
    start = time.time()

    for i in xrange(NUM_ITEMS):
        q.put('item %d' % i)
    for i in xrange(NUM_WORKERS):
        q.put(shutdown)

    for i in xrange(NUM_WORKERS):
        diesel.fork_child(worker)
    for i in xrange(NUM_WORKERS):
        dones.get()

    print 'all workers done in %.2f secs' % (time.time() - start)
    diesel.quickstop()
Example #40
0
def f():
    t1 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t2 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t3 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t4 = time()
    print request("http://example.iana.org/"), 'is found?'
    t5 = time()

    print 'First request should (probably) have been longer (tcp handshake) than subsequent 3 requests:'
    reduce(lambda t1, t2: sys.stdout.write("%.4f\n" % (t2 - t1)) or t2, (t1, t2, t3, t4, t5))

    quickstop()
Example #41
0
def do_echos():
	try:
		client = EchoClient('localhost', 6000)
	except:
		quickstop()
		return
	t = time.time()
	for x in xrange(1):
		msg = "hello, world #%s!\r\n" % x
		echo_result = client.echo(msg)
		print echo_result
	log.info('5000 loops in {0:.2f}s', time.time() - t)
	while True:
		pass
	quickstop()
Example #42
0
def f():
    t1 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t2 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t3 = time()
    print request("http://example.iana.org/missing"), 'is missing?'
    t4 = time()
    print request("http://example.iana.org/"), 'is found?'
    t5 = time()

    print 'First request should (probably) have been longer (tcp handshake) than subsequent 3 requests:'
    reduce(lambda t1, t2: sys.stdout.write("%.4f\n" % (t2 - t1)) or t2,
           (t1, t2, t3, t4, t5))

    quickstop()
Example #43
0
def interact_python():
    """Runs an interactive interpreter; halts the diesel app when finished."""
    globals_ = globals()
    env = {
        '__builtins__': globals_['__builtins__'],
        '__doc__': globals_['__doc__'],
        '__name__': globals_['__name__'],
        'diesel': diesel,
    }
    inp = create_line_input_stream(sys.stdin)

    def diesel_input(prompt):
        sys.stdout.write(prompt)
        sys.stdout.flush()
        return inp.get().rstrip('\n')

    code.interact(None, diesel_input, env)
    diesel.quickstop()
Example #44
0
def interact_python():
    """Runs an interactive interpreter; halts the diesel app when finished."""
    globals_ = globals()
    env = {
        '__builtins__':globals_['__builtins__'],
        '__doc__':globals_['__doc__'],
        '__name__':globals_['__name__'],
        'diesel':diesel,
    }
    inp = create_line_input_stream(sys.stdin)

    def diesel_input(prompt):
        sys.stdout.write(prompt)
        sys.stdout.flush()
        return inp.get().rstrip('\n')

    code.interact(None, diesel_input, env)
    diesel.quickstop()
def main():
    print "entering 'with' block using MontageClient ..."
    with MontageClient('localhost', 8087) as c:
        print "  got connection", c
        assert not c.is_closed
        print "  connection.is_closed ==", c.is_closed
    assert c.is_closed
    print "... left 'with' block"
    print "connection.is_closed ==", c.is_closed
    print
    print "entering 'with' block using MontageClient ..."
    try:
        with MontageClient('localhost', 8087) as c:
            print "  got connection", c
            assert not c.is_closed
            assert 0
    except AssertionError:
        assert c.is_closed
        print "exception caught, connection closed, all is well"
    diesel.quickstop()
def main():
    cl = MontageClient('localhost', 7078)

    refdata = UserInfo(uid=2)
    ref = cl.put('u-info', str(1), refdata.dumps())

    target1data = UserEvent(eid=3)
    target1 = cl.put('u-event', str(2), target1data.dumps())

    target2data = UserName(name="montage")
    target2 = cl.put('u-name', str(2), target2data.dumps())

    (refObj, values) = cl.get_by('u-info', str(1), ['u-event', 'u-name'])
    assert UserInfo(refObj.data) == refdata, "reference key found did not match"
    assert len(values) == 2, "incorrect num values"
    assert values[0] is not None, "Could not retrieve u-event data, nothing found"
    assert values[1] is not None, "Could not retrieve u-name data, nothing found"
    assert UserEvent(values[0].data) == target1data, "value 1 found did not match"
    assert UserName(values[1].data) == target2data, "value 2 found did not match"
    print "\npassed reference get identity\n"
    quickstop()
def main():
    cl = MontageClient('localhost', 7078)

    test_resolution(cl, 'u-info', '1')
    quickstop()
Example #48
0
 def interactive(addr):
     remote_console = LocalConsole()
     remote_console.interact(banner)
     diesel.quickstop()
Example #49
0
def stop_when_done():
    done.wait()
    print "Boom!"
    quickstop()
Example #50
0
def manage():
    cd.wait()
    quickstop()
Example #51
0
def late_consumer():
    sleep(4)
    consumer()
    quickstop()
Example #52
0
def interact_ipython():
    """Starts an IPython instance; halts the diesel app when finished."""
    IPShell(user_ns={'diesel': diesel}).mainloop()
    diesel.quickstop()
Example #53
0
 def f():
     sleep(0.05)
     fire("fizz!")
     sleep(0.05)
     WVPASS(v[0] == 0) # should not have woken up!
     quickstop()
Example #54
0
 def parent():
     v = [0]
     fork(tottering_child, v)
     sleep(0.1)
     WVPASS(v[0] == 1)
     quickstop()
Example #55
0
def killer():
    cd.wait()
    quickstop()
Example #56
0
    sleep_pool = ProcessPool(2, sleep_and_return)

    def main():
        def waiting(ident):
            print ident, "waiting ..."
            t = sleep_pool(4)
            print ident, "woken up after", t

        diesel.fork(waiting, 'a')
        diesel.fork(waiting, 'b')
        diesel.fork(waiting, 'c')
        for i in xrange(11):
            print "busy!"
            diesel.sleep(1)
        div = spawn(lambda x, y: x / y)
        try:
            div(1, 0)
        except ZeroDivisionError, e:
            diesel.log.error(e.original_traceback)
        print '^^ That was an intentional exception.'
        term(div)
        psleep = spawn(sleep_and_return)
        diesel.fork(psleep, 0.5)
        diesel.fork(psleep, 0.5)
        diesel.sleep(1)
        print '^^ That was an intentional exception.'
        diesel.quickstop()

    diesel.quickstart(sleep_pool.pool, main)
Example #57
0
 def run():
     print cargo.clear("foo")
     print cargo.set("foo", "bar")
     print cargo.lookup("foo")
     quickstop()
Example #58
0
def stop_it():
    quickstop()