def actor_event_loop(): while True: sleep(random.random() * max_sleep) if len(group) < max_group: group.append(name) wait('%s-group-started' % type) print "%s %s" % (name, task) wait('%s-group-done' % type)
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)
def get(self, waiting=True, timeout=None): start = time() while not self.inp and waiting: if timeout: remaining = timeout - (time() - start) if remaining <= 0: raise QueueTimeout() else: first(waits=[self.wait_id], sleep=remaining) else: wait(self.wait_id) if self.inp: return self.inp.popleft() elif not waiting: raise QueueEmpty()
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)
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()
def worker(): num_processed = 0 while True: val = diesel.wait(q) if val == shutdown: break num_processed += 1 fmt_args = (diesel.core.current_loop, num_processed) print "%s, worker done (processed %d items)" % fmt_args dones.put('done')
def sieged(): t = time.time() while True: n = wait('bam') if n % 10000 == 0: log.info(n) if n == 50000: delt = time.time() - t log.info("50,000 messages in %.3fs (%.1f/s)" % (delt, 50000 / delt)) a.halt()
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')
def worker(myid): while True: # Test both queue.get and wait() on queue (both are valid # APIs for getting items from the queue). The results should # be the same. if random.random() > 0.5: v = self.queue.get() else: v = diesel.wait(self.queue) self.results.append(v) self.handled[myid] += 1 self.done.tick()
def wait_and_notify(self, collection, subscriber): """Wait for published info that subscriber cares about and notify them. The notification might be instant in the case of already published information or it might occur some time in the future. """ chans = self.subscribers[subscriber] if collection: # filter the channels by the passed collection chans = set([c for c in chans if c[0] == collection]) ready = [self.channels[c].get(subscriber) for c in chans] if not any(ready): chanupdates = tuple(('update',) + chan for chan in chans) yield tuple(wait(updates) for updates in chanupdates) ready = [self.channels[c].get(subscriber) for c in chans] all_ready = "".join(ready) rlen = len(all_ready) resp = "%s%s" % (struct.pack('<i', rlen), all_ready) yield up(resp)
def acquire(self): while self.count == 0: wait(self.wait_id) self.count -= 1
def go(): diesel.wait('ready') for i in xrange(N): self.queue.put(i)
def acquire(self): if self.count == 0: wait(self) else: self.count -= 1
def actor(): while True: board = yield wait('board-received') #print "got the board..." yield fire('move-made', tron.move(random_move(board)))
def w(): while True: wait("boom!") v[0] += 1
def waiting_green_thread(wait_id, done): diesel.wait(wait_id) done.append(True)
def handle(): while True: wait(event) print "Saw %r" % event sleep(3 * random.random())