Exemplo n.º 1
0
Arquivo: chat.py Projeto: dowski/aspen
def chat_server(addr):
    my_nick = until_eol().strip()
    while True:
        ev, val = first(until_eol=True, waits=['chat_message'])
        if ev == 'until_eol':
            fire('chat_message', (my_nick, val.strip()))
        else:
            nick, message = val
            send("<%s> %s\r\n"  % (nick, message))
Exemplo n.º 2
0
def chat_server(addr):
    my_nick = until_eol().strip()
    while True:
        evt, data = first(until_eol=True, waits=['chat_message'])
        if evt == 'until_eol':
            fire('chat_message', (my_nick, data.strip()))
        else:
            nick, message = data
            send("<%s> %s\r\n" % (nick, message))
Exemplo n.º 3
0
def chat_server(addr):
    my_nick = until_eol().strip()
    while True:
        evt, data = first(until_eol=True, waits=["chat_message"])
        if evt == "until_eol":
            fire("chat_message", (my_nick, data.strip()))
        else:
            nick, message = data
            send("<%s> %s\r\n" % (nick, message))
Exemplo n.º 4
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()
Exemplo n.º 5
0
 def query_20_times():
     d = MongoClient(HOST, PORT)
     counts = []
     wait('deleted')
     for i in range(20):
         with d.diesel.test.find({'type':'test'}, limit=500) as cursor:
             while not cursor.finished:
                 counts.append(len(cursor.more()))
         if not i:
             wait('main.done')
     assert 0 in counts, counts
     assert 500 in counts, counts
     print "20 concurrent queries - passed"
     fire('queries.done', True)
Exemplo n.º 6
0
    def handle_transition(self, manual=False):
        '''Handle state change.
        '''
        if not manual:
            diesel.fire(self)
        events = self.socket.getsockopt(zmq.EVENTS)
        if events & zmq.POLLIN:
            self.read_gate.set()
        else:
            self.read_gate.clear()

        if events & zmq.POLLOUT:
            self.write_gate.set()
        else:
            self.write_gate.clear()
Exemplo n.º 7
0
    def handle_transition(self, manual=False):
        '''Handle state change.
        '''
        if not manual:
            diesel.fire(self)
        events = self.socket.getsockopt(zmq.EVENTS)
        if events & zmq.POLLIN:
            self.read_gate.set()
        else:
            self.read_gate.clear()

        if events & zmq.POLLOUT:
            self.write_gate.set()
        else:
            self.write_gate.clear()
Exemplo n.º 8
0
    def subq(self, classes):
        if type(classes) not in (set, list, tuple):
            classes = [classes]

        q = Queue()

        for cls in classes:
            self.sub_adds.append((cls, q))

        fire(self.sub_wake_signal)

        try:
            yield q
        finally:
            for cls in classes:
                self.sub_rms.append((cls, q))
Exemplo n.º 9
0
 def publish_and_update(self, collection, payload):
     """Publish an update and yield None to relay the data to the backend."""
     upsert, raw_bson = payload[:4], payload[4:]
     spec, raw_doc = _bson_to_dict(raw_bson)
     uid = self.channels[(collection, str(spec))].update(raw_doc)
     yield fire(('update', collection, str(spec)))
     yield up(None)
Exemplo n.º 10
0
    def subq(self, classes):
        if type(classes) not in (set, list, tuple):
            classes = [classes]

        q = Queue()

        for cls in classes:
            self.sub_adds.append((cls, q))

        fire(self.sub_wake_signal)

        try:
            yield q
        finally:
            for cls in classes:
                self.sub_rms.append((cls, q))
Exemplo n.º 11
0
def chat_server(addr):
    my_nick = (yield until_eol()).strip()
    while True:
        my_message, other_message = yield (until_eol(), wait('chat_message'))
        if my_message:
            yield fire('chat_message', (my_nick, my_message.strip()))
        else:
            nick, message = other_message
            yield "<%s> %s\r\n"  % (nick, message)
Exemplo n.º 12
0
def getboard():
    buf = ''
    yield sleep(0.1)
    while True:
        #print move_made
        #print "waiting for stdin ..."
        board, buf = tron.Board.read(buf)
        if not board:
            break
        yield fire('board-received', board)
        #print "fired board"
        yield wait('move-made')
Exemplo n.º 13
0
def test_wait_tokens_dont_accumulate_forever():
    """Wait tokens and related structures should be disposed of after use.

    They are tracked in a dictionary in the internal
    diesel.events.WaitPool. If a wait_id has no more objects waiting on it,
    it should be removed from that dictionary along with the set of waiting
    objects.

    """
    done = []
    wait_ids = []
    expected_length = len(diesel.runtime.current_app.waits.waits)
    for i in xrange(50):
        wait_id = uuid.uuid4().hex
        diesel.fork(waiting_green_thread, wait_id, done)
        diesel.sleep()
        wait_ids.append(wait_id)
    for wait_id in wait_ids:
        diesel.fire(wait_id)
        diesel.sleep()
    while len(done) != 50:
        diesel.sleep(0.1)
    actual_length = len(diesel.runtime.current_app.waits.waits)
    assert actual_length == expected_length, actual_length
Exemplo n.º 14
0
def test_wait_tokens_dont_accumulate_forever():
    """Wait tokens and related structures should be disposed of after use.

    They are tracked in a dictionary in the internal
    diesel.events.WaitPool. If a wait_id has no more objects waiting on it,
    it should be removed from that dictionary along with the set of waiting
    objects.

    """
    done = []
    wait_ids = []
    expected_length = len(diesel.runtime.current_app.waits.waits)
    for i in xrange(50):
        wait_id = uuid.uuid4().hex
        diesel.fork(waiting_green_thread, wait_id, done)
        diesel.sleep()
        wait_ids.append(wait_id)
    for wait_id in wait_ids:
        diesel.fire(wait_id)
        diesel.sleep()
    while len(done) != 50:
        diesel.sleep(0.1)
    actual_length = len(diesel.runtime.current_app.waits.waits)
    assert actual_length == expected_length, actual_length
Exemplo n.º 15
0
 def messages_exist(self):
     '''Handle state change.
     '''
     self.read_gate.set()
     diesel.fire(self)
Exemplo n.º 16
0
def gunner():
    x = 1
    while True:
        fire('bam', x)
        x += 1
        sleep()
Exemplo n.º 17
0
Arquivo: lock.py Projeto: dowski/aspen
 def release(self):
     self.count += 1
     fire(self.wait_id)
Exemplo n.º 18
0
 def f():
     sleep(0.05)
     fire("fizz!")
     done.set()
Exemplo n.º 19
0
Arquivo: lock.py Projeto: yadra/diesel
 def release(self):
     self.count += 1
     fire(self)
Exemplo n.º 20
0
 def f():
     sleep(0.05)
     fire("fizz!")
     sleep(0.05)
     WVPASS(v[0] == 0) # should not have woken up!
     quickstop()
Exemplo n.º 21
0
 def pure_db_action():
     d = MongoClient(HOST, PORT)
     print d.list_databases()
     print d.drop_database('diesel')
     fire('deleted')
     d.diesel.test.insert({'name':'dowski', 'state':'OH'})
     d.diesel.test.insert({'name':'jamwt', 'state':'CA'})
     d.diesel.test.insert({'name':'mrshoe', 'state':'CA'})
     with (d.diesel.test.find({'state':'OH'})) as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert res[0]['name'] == 'dowski', res
             assert res[0]['state'] == 'OH', res
             print "query1 (simple where) passed"
     with d.diesel.test.find({'state':'CA'}) as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert len(res) == 2, res
             assert res[0]['name'] == 'jamwt', res
             assert res[1]['name'] == 'mrshoe', res
             print "query2 (simple where) passed"
     with (d.diesel.test.find()) as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert len(res) == 3, res
             assert [r['state'] for r in res] == ['OH', 'CA', 'CA'], res
             print "query3 (query all) passed"
     print "updating"
     d.diesel.test.update({'name':'dowski'}, {'$set':{'kids':2}})
     with d.diesel.test.find() as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert [r['kids'] for r in res if 'kids' in r] == [2], res
             print "query4 (verify update) passed"
     print "inserting"
     d.diesel.test.insert({'name':'mr t', 'state':'??'})
     with d.diesel.test.find({'name':'mr t'}, ['state']) as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert len(res) == 1, res
             assert 'name' not in res[0], res
             assert res[0]['state'] == '??', res
             print "query5 (verify insert) passed"
     print "deleting"
     d.diesel.test.delete({'name':'mr t'})
     with d.diesel.test.find({'name':'mr t'}, ['state']) as cursor:
         while not cursor.finished:
             res = cursor.more()
             assert res == [], res
             print "query6 (verify delete) passed"
     print "inserting 10000"
     d.diesel.test.insert([{'code':i, 'type':'test'} for i in xrange(10000)])
     count = 0
     passes = 0
     with d.diesel.test.find({'type':'test'}) as cursor:
         while not cursor.finished:
             count += len(cursor.more())
             passes += 1
     assert count == 10000, count
     assert passes == 2, passes
     print "query7 (get_more) passed"
     print "inserting"
     d.diesel.test.insert([{'letter':'m'}, {'letter':'b'}, {'letter':'k'}])
     with d.diesel.test.find({'letter': {'$exists':True}}) as cursor:
         cursor.sort('letter', Ops.DESCENDING)
         while not cursor.finished:
             res = cursor.more()
             assert len(res) == 3, res
             assert [r['letter'] for r in res] == ['m', 'k', 'b'], res
             print "query8 (sorting) passed"
     with d.diesel.test.find({'type':'test'}) as cursor:
         n = cursor.count()
         assert n == 10000, n
         print "query9 (count) passed"
     n = 0
     for rec in  d.diesel.test.find({'type':'test'}):
         n += 1
     assert n == 10000, n
     print "query10 (cursor iteration) passed"
     fire('main.done', True)
Exemplo n.º 22
0
def work_with_group(name, group, message):
    print "Ho! Ho! Ho! Let's", message
    fire('%s-group-started' % name)
    sleep(random.random() * 3)
    excuse_group(name, group)
Exemplo n.º 23
0
 def messages_exist(self):
     '''Handle state change.
     '''
     self.read_gate.set()
     diesel.fire(self)
Exemplo n.º 24
0
Arquivo: lock.py Projeto: dowski/aspen
 def release(self):
     self.count += 1
     fire(self.wait_id)
Exemplo n.º 25
0
 def set(self):
     if not self.is_set:
         self.is_set = True
         fire(self)
Exemplo n.º 26
0
 def release(self):
     self.count += 1
     fire(self)
Exemplo n.º 27
0
def pump():
    for i in xrange(5):
        fire('thing')
        print "Fired 'thing'"
        sleep(1)
    quickstop()
Exemplo n.º 28
0
 def trigger(self):
     diesel.sleep()
     diesel.fire('ready')
     super(TestConsumersOnEmptyQueue, self).trigger()
Exemplo n.º 29
0
def gunner():
    x = 1
    while True:
        fire('bam', x)
        x += 1
        sleep()
Exemplo n.º 30
0
 def put(self, i=None):
     self.inp.append(i)
     fire(self)
Exemplo n.º 31
0
def actor():
    while True:
        board = yield wait('board-received')
        #print "got the board..."
        yield fire('move-made', tron.move(random_move(board)))
Exemplo n.º 32
0
            def __init__(self):
                for cls in classes:
                    hb.sub_adds.append((cls, q))

                fire(hb.sub_wake_signal)
Exemplo n.º 33
0
def excuse_group(name, group):
    group[:] = []
    fire('%s-group-done' % name, True)
Exemplo n.º 34
0
 def set(self):
     if not self.is_set:
         self.is_set = True
         fire(self)
Exemplo n.º 35
0
 def put(self, i=None):
     self.inp.append(i)
     fire(self.wait_id)
Exemplo n.º 36
0
 def f():
     sleep(0.05)
     fire("boom!")
     sleep(0.05)
     fire("boom!")
     done.set()
Exemplo n.º 37
0
            def __init__(self):
                for cls in classes:
                    hb.sub_adds.append((cls, q))

                fire(hb.sub_wake_signal)
Exemplo n.º 38
0
 def trigger(self):
     diesel.sleep()
     diesel.fire('ready')
     super(TestConsumersOnEmptyQueue, self).trigger()