def l(): t = time() sleep(0.3) delt = time() - t print delt WVPASS(delt > 0.275 and delt < 0.325) quickstop()
def send_message(): outsock = DieselZMQSocket(zctx.socket(zmq.DEALER), connect="tcp://127.0.0.1:5000") for x in xrange(500000): outsock.send("yo dawg %s" % x) if x % 1000 == 0: sleep()
def putter(): log = glog.name("putter") log.info("putting 100000 things on queue") for x in xrange(100000): q.put(x) sleep()
def wait_for_signal(): log = diesel.log.name('dummy') log.min_level = diesel.loglevels.INFO install_console_signal_handler() while True: log.info("sleeping") diesel.sleep(5)
def sync_loop(): global sync with synchronized(): sync += 1 sleep(random.random()) sync -= 1 print 'SYNC', sync
def coordinator(): # Pretend to do something ... sleep(3) # Done, fire the event. print "Coordinator done." ev.set()
def l(): sleep(0.05) cur = v[0] sleep() now = v[0] WVPASS(now == cur + 1) quickstop()
def _loop(): client = EchoClient("localhost", 8013) while 1: bar = client.echo_whatup() tms = time.asctime() log.info("[%s] %s: (whatup) remote service said %r" % (tms, n, bar)) sleep(3)
def l(): t = time() sleep(0.05) WVPASS(v[0] == 2) sleep(0.1) WVPASS(v[0] == 4) quickstop()
def p(): for x in xrange(c): q.put(x) sleep(1) WVPASS(done[0] == 1) quickstop()
def dependent_child(got_exception): try: sleep(50) except ParentDiedException: got_exception[0] = 1 else: got_exception[0] = 0
def maker(): for x in xrange(500000): d.dispatch(x) if x % 10000 == 0: sleep() log.info("values: {0}", r) quickstop()
def delay_echo_server(addr): inp = until_eol() for x in xrange(4): sleep(2) send(str(x) + '\r\n') send("you said %s" % inp)
def putter(): log = glog.sublog("putter", glog.info) log.info("putting 100000 things on log") for x in xrange(100000): q.put(x) sleep()
def nolocks(cd): global v for x in xrange(500): s = v sleep() v = s + 1 cd.tick()
def _loop(): client = EchoClient("localhost", 8013) while 1: bar = client.echo("foo %s" % n) tms = time.asctime() log.info("[%s] %s: remote service said %r" % (tms, n, bar)) sleep(2)
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()
def santa(): while True: deer_ready, elves_ready = len(deer_group) == 9, len(elf_group) == 3 if deer_ready: work_with_group('deer', deer_group, 'deliver toys') if elves_ready: work_with_group('elf', elf_group, 'meet in my study') sleep(random.random() * 1)
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 delayed_value(self): assert self.delay, \ "This connection requires more items in its delay list for further requests." delay = self.delay.pop(0) if delay is not None: print diesel.sleep(delay) if self.waiting_callback: self.waiting_callback('expected value %s\r\n' % self.conn_id)
def sync_loop(): global sync id = random.random() with synchronized(): sync += 1 sleep(random.random()) sync -= 1 print "SYNC", sync
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()
def not_always_busy_worker(): with CPUStats() as stats: for _ in xrange(12): for i in xrange(10000000): # do some work to forward cpu seconds pass sleep(0.1) # give up control print "cpu seconds ", stats.cpu_seconds
def send_message(): global t outsock = DieselZMQSocket(zctx.socket(zmq.DEALER), connect="inproc://foo") t = time.time() for x in xrange(500000): outsock.send("yo dawg %s" % x) if x % 1000 == 0: sleep()
def _send_op(self, op): while True: try: op() except pynitro.NitroFull: diesel.sleep(0.2) else: self.sent += 1 return
def dependent_child(): try: sleep(50) except ParentDiedException: got_exception = 1 else: got_exception = 0 WVPASS(got_exception) quickstop()
def withlocks(locker, cd): global v for x in xrange(50): with locker.hold('v'): s = v sleep() v = s + 1 if x % 10 == 0: print x cd.tick()
def track_cpu_stats(): pid = os.getpid() def append_stats(): rawstats = subprocess.Popen(['ps -p %d -f' % pid], shell=True, stdout=subprocess.PIPE).communicate()[0] header, data = rawstats.split('\n', 1) procstats = [d for d in data.split(' ') if d] cpustats.append(int(procstats[3])) while True: diesel.sleep(1) diesel.thread(append_stats)
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()
def setup(self): self.done = Countdown(10) self.fan = Fanout() self.subscriber_data = {} for x in xrange(10): diesel.fork(self.subscriber) diesel.sleep() for i in xrange(10): self.fan.pub(i) self.done.wait()
def manage(): sleep(10) a.halt()
def free_loop(): global free free += 1 sleep(random.random()) free -= 1 print 'FREE', free
def parent(): v = [0] fork(tottering_child, v) sleep(0.1) WVPASS(v[0] == 1) quickstop()
def tottering_child(v): v[0] += 1 sleep(10)
def parent(): fork_child(dependent_child) sleep(0.1) a = b # undef
def p(): sleep(0.9) WVPASS(v[0] > 1) a.halt()
def loop(): t = time.time() sleep(1) acc.duration = time.time() - t touch()
def stuff(): while True: print "doing stuff!" sleep(0.01)
def tick(): while True: print "Other diesel stuff" sleep(1)
def loop(): t = time.time() sleep(1) acc.durations.append(time.time() - t) touch()
def gunner(): x = 1 while True: fire('bam', x) x += 1 sleep()