Пример #1
0
def send_data_to_front_end(message_id):
    endTime = datetime.datetime.now()
    if ((endTime - send_data_to_front_end.startTime).microseconds > TIME_RATE):
        if PRINT_CHAR_FOR_BACK_TO_FRONT_UPDATE:
            debug.print_char('>') # sending JSON data to front-end
	
        if (no_packet_received()):
            broadcast(json_ERRO('ERRO', 0, "no packet revceived"))
            # print "No packet received"
        else:
            broadcast(check_before_send(parse_data.ADIS_mess, 'ADIS'))
            broadcast(parse_data.last_GPS_mess)
            broadcast(parse_data.last_MPL3_mess)
            broadcast(parse_data.last_MPU9_mess)
            broadcast(check_before_send(parse_data.last_ROLL_mess, 'ROLL'))
        broadcast(check_before_send(parse_data.packet_analyze, 'Analyze'))
        init_data()
    send_data_to_front_end.startTime = datetime.datetime.now()            
Пример #2
0
        self.in_q.put(item)

    def run(self):
        self.target(genfrom_queue(self.in_q))


# Example use
if __name__ == '__main__':
    from follow import *
    from apachelog import *
    from broadcast import *

    def find_404(log):
        for r in (r for r in log if r['status'] == 404):
            print r['status'], r['datetime'], r['request']

    def bytes_transferred(log):
        total = 0
        for r in log:
            total += r['bytes']
            print "Total bytes", total

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow(open("run/foo/access-log"))  # Follow a log
    log = apache_log(lines)  # Turn into records
    broadcast(log, [c1, c2])  # Broadcast to consumers
Пример #3
0
        self.target(self.generate())

# Example Use

if __name__ == '__main__':
    from follow import *
    from apachelog import *
    from broadcast import *
    
    def find_404(log):
        r404 = (r for r in log if r['status'] == 404)
        for r in r404:
            print r['status'],r['datetime'],r['request']

    def bytes_transferred(log):
        total = 0
        for r in log:
            total += r['bytes']
            print "Total bytes", total
            
    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()
    
    lines = follow(open("run/foo/access-log"))
    log   = apache_log(lines)
    broadcast(log,[c1,c2])


Пример #4
0
    def run(self):
        self.target(self.generate())


# Example Use

if __name__ == '__main__':
    from follow import *
    from apachelog import *
    from broadcast import *

    def find_404(log):
        r404 = (r for r in log if r['status'] == 404)
        for r in r404:
            print r['status'], r['datetime'], r['request']

    def bytes_transferred(log):
        total = 0
        for r in log:
            total += r['bytes']
            print "Total bytes", total

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow(open("run/foo/access-log"))
    log = apache_log(lines)
    broadcast(log, [c1, c2])
Пример #5
0
#
# An example of using co-routines to define consumers for the Apache log data

from consumer import *
from apachelog import *
from follow import *
from broadcast import *


@consumer
def find_404():
    while True:
        r = (yield)
        if r['status'] == 404:
            print r['status'], r['datetime'], r['request']


@consumer
def bytes_transferred():
    total = 0
    while True:
        r = (yield)
        total += r['bytes']
        print "Total bytes", total


lines = follow(open("run/foo/access-log"))
log = apache_log(lines)

broadcast(log, [find_404(), bytes_transferred()])
Пример #6
0
        self.s.connect(addr)
    def send(self,item):
        pitem = pickle.dumps(item)
        self.s.sendall(pitem)
    def close(self):
        self.s.close()

# Example use.  This requires you to run receivefrom.py first.

if __name__ == '__main__':
    from broadcast import *
    from follow import *
    from apachelog import *

    # A class that sends 404 requests to another host
    class Stat404(NetConsumer):
        def send(self,item):
            if item['status'] == 404:
                NetConsumer.send(self,item)
    
    stat404 = Stat404(("",15000))
    
    lines = follow(open("run/foo/access-log"))
    log   = apache_log(lines)
    broadcast(log,[stat404])


    
    
    
Пример #7
0
    def __init__(self, addr):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect(addr)

    def send(self, item):
        pitem = pickle.dumps(item)
        self.s.sendall(pitem)

    def close(self):
        self.s.close()


# Example use.  This requires you to run receivefrom.py first.

if __name__ == '__main__':
    from broadcast import *
    from follow import *
    from apachelog import *

    # A class that sends 404 requests to another host
    class Stat404(NetConsumer):
        def send(self, item):
            if item['status'] == 404:
                NetConsumer.send(self, item)

    stat404 = Stat404(("", 15000))

    lines = follow(open("run/foo/access-log"))
    log = apache_log(lines)
    broadcast(log, [stat404])
Пример #8
0
# logcoroutine.py
#
# An example of using co-routines to define consumers for the Apache log data

from consumer import *
from apachelog import *
from follow import *
from broadcast import *

@consumer
def find_404():
    while True:
        r = (yield)
        if r['status'] == 404:
            print r['status'],r['datetime'],r['request']

@consumer
def bytes_transferred():
    total = 0
    while True:
        r = (yield)
        total += r['bytes']
        print "Total bytes", total

lines = follow(open("run/foo/access-log"))
log   = apache_log(lines)

broadcast(log, [find_404(),bytes_transferred()])
Пример #9
0
#
# An example of using co-routines to define consumers for the Apache log data

from consumer import *
from apachelog import *
from follow import *
from broadcast import *


@consumer
def find_404():
    while True:
        r = (yield)
        if r['status'] == 404:
            print r['status'], r['datetime'], r['request']


@consumer
def bytes_transferred():
    total = 0
    while True:
        r = (yield)
        total += r['bytes']
        print "Total bytes", total


lines = follow(open("run/foo/access-log"))
log = apache_log(lines)

broadcast(log, [find_404(), bytes_transferred()])  # 使用多个消费者,但每个消费者没有用线程
Пример #10
0
         self.target = target
    def send(self,item):
         self.in_q.put(item)
    def run(self):
        self.target(genfrom_queue(self.in_q))

# Example use
if __name__ == '__main__':
    from follow import *
    from apachelog import *
    from broadcast import *

    def find_404(log):
        for r in (r for r in log if r['status'] == 404):
            print r['status'],r['datetime'],r['request']

    def bytes_transferred(log):
        total = 0
        for r in log:
            total += r['bytes']
            print "Total bytes", total

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow(open("run/foo/access-log"))  # Follow a log
    log   = apache_log(lines)           # Turn into records
    broadcast(log,[c1,c2])         # Broadcast to consumers