Example #1
0
def maker():
    for x in xrange(500000):
        d.dispatch(x)
        if x % 10000 == 0:
            sleep()
            log.info("values: {0}", r)
    quickstop()
Example #2
0
def req_loop():
    with HttpClient('www.jamwt.com', 80) as client:
        heads = HttpHeaders()
        heads.set('Host', 'www.jamwt.com')
        log.info(client.request('GET', '/Py-TOC/', heads))
        log.info(client.request('GET', '/', heads))
    a.halt()
Example #3
0
 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)
Example #4
0
File: app.py Project: wmoss/diesel
    def run(self):
        '''Start up an Application--blocks until the program ends
        or .halt() is called.
        '''
        self._run = True
        log.warn('Starting diesel <%s>'
                % self.hub.describe)

        for s in self._services:
            s.bind_and_listen()
            s.register(self)

        for l in self._loops:
            self.hub.schedule(l.wake)

        self.setup()
        def main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warn("-- SystemExit raised.. exiting main loop --")
                    break
                except KeyboardInterrupt:
                    log.warn("-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warn("-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception, e:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #5
0
def follow_loop():
    global count
    global files
    count += 1
    client, heads = get_client()
    while True:
        try:
            lpath = links.next()
        except StopIteration:
            count -= 1
            if not count:
                stop()
            break
        log.info(" -> %s" % lpath )
        for x in xrange(2):
            try:
                if client.is_closed:
                    client, heads = get_client()
                code, heads, body = client.request('GET', lpath, heads)
            except ConnectionClosed:
                pass
            else:
                write_file(lpath, body)
                files +=1
                break
Example #6
0
 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)
Example #7
0
def req_loop():
    with HttpClient("www.jamwt.com", 80) as client:
        heads = HttpHeaders()
        heads.set("Host", "www.jamwt.com")
        log.info(client.request("GET", "/Py-TOC/", heads))
        log.info(client.request("GET", "/", heads))
    a.halt()
Example #8
0
def maker():
    for x in xrange(500000):
        d.dispatch(x)
        if x % 10000 == 0:
            sleep()
            log.info("values: {0}", r)
    quickstop()
Example #9
0
    def run(self):
        """Start up an Application--blocks until the program ends
        or .halt() is called.
        """
        self._run = True
        logmod.set_current_application(self)
        log.info("Starting diesel application")

        for s in self._services:
            s.bind_and_listen()
            self.hub.register(s.sock, s.accept_new_connection, None)
        for l in self._loops:
            l.iterate()

        self.setup()
        while self._run:
            try:
                self.hub.handle_events()
            except SystemExit:
                log.warn("-- SystemExit raised.. exiting main loop --")
                break
            except KeyboardInterrupt:
                log.warn("-- KeyboardInterrupt raised.. exiting main loop --")
                break
            except Exception, e:
                log.error("-- Unhandled Exception in main loop --")
                log.error(traceback.format_exc())
Example #10
0
 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)
Example #11
0
def blocker(taskid, sleep_time):
    while True:

        def f():
            time.sleep(sleep_time)

        thread(f)
        log.info('yo! {0} from {1} task', time.time(), taskid)
Example #12
0
 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)
Example #13
0
def do_echos():
    client = EchoClient('localhost', 8000, ssl_ctx=SSL.Context(SSL.TLSv1_METHOD))
    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 %.2fs' % (time.time() - t))
    app.halt()
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():
    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 #16
0
def req_loop():
    global links
    client, heads = get_client()
    log.info(path)
    code, heads, body = client.request('GET', path, heads)
    write_file(path, body)
    links = get_links(body)
    for x in xrange(CONCURRENCY):
        a.add_loop(Loop(follow_loop))
Example #17
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 #18
0
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()
Example #19
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 #20
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 #21
0
    def bind_and_listen(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # unsure if the following two lines are necessary for UDP
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setblocking(0)

        try:
            log.info("binding to port %s" % str(self.port))
            sock.bind((self.iface, self.port))
        except socket.error, e:
            self.handle_cannot_bind(str(e))
Example #22
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 #23
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 #24
0
    def run(self):
        '''Start up an Application--blocks until the program ends
        or .halt() is called.
        '''
        profile = os.environ.get('DIESEL_PROFILE', '').lower() in YES_PROFILE
        track_gc = os.environ.get('TRACK_GC', '').lower() in YES_PROFILE
        track_gc_leaks = os.environ.get('TRACK_GC_LEAKS',
                                        '').lower() in YES_PROFILE
        if track_gc:
            gc.set_debug(gc.DEBUG_STATS)
        if track_gc_leaks:
            gc.set_debug(gc.DEBUG_LEAK)

        self._run = True
        log.warning('Starting diesel <{0}>', self.hub.describe)

        for s in self._services:
            s.bind_and_listen()
            s.register(self)

        for l in self._loops:
            self.hub.schedule(l.wake)

        self.setup()

        def _main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warning("-- SystemExit raised.. exiting main loop --")
                    raise
                except KeyboardInterrupt:
                    log.warning(
                        "-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warning(
                        "-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception, e:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #25
0
    def run(self):
        '''Start up an Application--blocks until the program ends
        or .halt() is called.
        '''
        profile = os.environ.get('DIESEL_PROFILE', '').lower() in YES_PROFILE
        track_gc = os.environ.get('TRACK_GC', '').lower() in YES_PROFILE
        track_gc_leaks = os.environ.get('TRACK_GC_LEAKS', '').lower() in YES_PROFILE
        if track_gc:
            gc.set_debug(gc.DEBUG_STATS)
        if track_gc_leaks:
            gc.set_debug(gc.DEBUG_LEAK)

        self._run = True
        log.warning('Starting diesel <{0}>', self.hub.describe)

        for s in self._services:
            s.bind_and_listen()
            s.register(self)

        for l in self._loops:
            self.hub.schedule(l.wake)

        self.setup()

        def _main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warning("-- SystemExit raised.. exiting main loop --")
                    raise
                except KeyboardInterrupt:
                    log.warning("-- KeyboardInterrupt raised.. exiting main loop --")
                    if __debug__:
                        raise
                    break
                except ApplicationEnd:
                    log.warning("-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception, e:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #26
0
File: app.py Project: mvaled/diesel
        def _main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warning("-- SystemExit raised.. exiting main loop --")
                    raise
                except KeyboardInterrupt:
                    log.warning("-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warning("-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #27
0
 def is_complete(self):
     if (self.num_packets < 0):
         return False
     if len(self.packets) < self.num_packets:
         return False
     for packet in self.packets:
         if packet is None:
             return False
     _DEBUG_RELIABLE_UDP and log.info("multipacket complete multiseqid: %d" % self.multi_seq_id)
     return True
Example #28
0
File: app.py Project: dowski/aspen
    def run(self):
        '''Start up an Application--blocks until the program ends
        or .halt() is called.
        '''
        self._run = True
        log.info('Starting diesel application')

        for s in self._services:
            s.bind_and_listen()
            self.hub.register(
                s.sock, s.accept_new_connection, None,
                self.global_bail("low-level socket error on bound service"))

        for l in self._loops:
            self.hub.schedule(l.wake)

        self.setup()

        def main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warn("-- SystemExit raised.. exiting main loop --")
                    break
                except KeyboardInterrupt:
                    log.warn(
                        "-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warn("-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception, e:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #29
0
    def run(self):
        '''Start up an Application--blocks until the program ends
        or .halt() is called.
        '''
        self._run = True
        log.warning('Starting diesel <{0}>', self.hub.describe)

        for s in self._services:
            s.bind_and_listen()
            s.register(self)

        for l in self._loops:
            self.hub.schedule(l.wake)

        self.setup()

        def main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warning("-- SystemExit raised.. exiting main loop --")
                    raise
                except KeyboardInterrupt:
                    log.warning(
                        "-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warning(
                        "-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception, e:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
Example #30
0
 def needs_msg(self, multi_seq_id, msg_seq, msg_len, msg):
     if self.multi_seq_id == multi_seq_id:
         if self.num_packets > 0 and msg_len < 0:
         #if is_seq_in_range(msg_seq, self.first_seq, self.last_seq) and multi_seq_id == self.multi_seq_id:
             #assert(msg_len < 0) # should only be here if we have already got the first packet!
             try:
                 if self.packets[-msg_len] is None:
                     self.packets[-msg_len] = msg
             except:
                 print self.packets
                 print "msglen %d, len packets %d" % (msg_len, len(self.packets))
                 ipdb.set_trace()
                 raise
         else:
             _DEBUG_RELIABLE_UDP and log.info("adding to existing PendingMultipacket multi_seq_id %d, msg_len %d" % (multi_seq_id, msg_len))
             if msg_len >= 0: # this is the first message
                 self.packets[0] = msg
                 #self.first_seq = msg_seq
                 self.num_packets = ReliableHeader.calc_num_packets(msg_len)
                 self.multi_seq_id = multi_seq_id
                 self._grow_num_packets(self.num_packets)
                 #self.last_seq = seq_add(self.first_seq, self.num_packets) #self.first_seq + self.num_packets
                 _DEBUG_RELIABLE_UDP and log.info("NEW FIRST PACKET FOR: PendingMultipacket ID %d, num_packets %d, FIRST: %d, LAST: %d" % (self.multi_seq_id, self.num_packets, msg_seq, msg_seq - 1 + self.num_packets))
             else:
                 #NOTE: we've already received a packet, which also wasn't the first packet, and neither is this. add to our incomplete packets
                 check_max = -msg_len + 1
                 self._grow_num_packets(check_max)
                 try:
                     self.packets[-msg_len] = msg
                 except:
                     print self.packets
                     ipdb.set_trace()
                     self._grow_num_packets(check_max)
                     raise
         return True
     return False
Example #31
0
 def __init__(self, multi_seq_id, msg_seq, msg_len, initial_msg):
     if (msg_len < 0):
         #first_seq = seq_add(msg_seq, -msg_len) #msg_seq + (-msg_len)
         #self.last_seq = -1
         self.num_packets = -1
         self.packets = [None for i in range(-msg_len + 1)]
         self.packets[-msg_len] = initial_msg
         self.multi_seq_id = multi_seq_id
     else:
         #self.first_seq = msg_seq
         self.num_packets = ReliableHeader.calc_num_packets(msg_len)
         #self.last_seq = seq_add(msg_seq, self.num_packets) #msg_seq + self.num_packets
         self.packets = [None for i in range( self.num_packets)]
         self.packets[0] = initial_msg
         self.multi_seq_id = multi_seq_id
         _DEBUG_RELIABLE_UDP and log.info("NEW PendingMultipacket ID %d, num_packets %d, FIRST: %d, LAST: %d" % (multi_seq_id, self.num_packets, msg_seq, msg_seq - 1 + self.num_packets))
Example #32
0
def req_loop():
    for path in ['/Py-TOC', '/']:
        with HttpClient('www.jamwt.com', 80) as client:
            heads = {'Host' : 'www.jamwt.com'}
            log.info(str(client.request('GET', path, heads)))
    quickstop()
Example #33
0
def blocker(taskid, sleep_time):
    while True:
        def f():
            time.sleep(sleep_time)
        thread(f)
        log.info('yo! {0} from {1} task', time.time(), taskid)
Example #34
0
def stop():
    log.info("Fetched %s files in %.3fs with concurrency=%s" % (files, time.time() - t, CONCURRENCY))
    a.halt() # stop application
Example #35
0
def req_loop():
    with HttpClient('www.jamwt.com', 80) as client:
        heads = {'Host' : 'www.jamwt.com'}
        log.info(str(client.request('GET', '/Py-TOC/', heads)))
        log.info(str(client.request('GET', '/', heads)))
    quickstop()
Example #36
0
 def on_close(self):
     log.info("ouch!  closed!")
Example #37
0
 def on_close(self):
     log.info('ouch!  closed!')