Esempio n. 1
0
def sendreq(site, bytes):
    result = []

    def actually_send():
        socket = FakeSocket(bytes)
        waiter = coro.coroutine_cond()
        server = FakeServer(waiter)
        log = coro.coroutine_logger('tests')
        output = cStringIO.StringIO()
        log.addHandler(logging.StreamHandler(output))
        http = corohttpd.HttpProtocol(args=(socket, ('<fake>', 0), server,
                                            [site]),
                                      log=log)
        http.start()
        waiter.wait(0.01)
        if socket.pushed.startswith('HTTP/1.1 500'):
            output.seek(0)
            print output.read()
        result.append(socket.pushed)

    coro.spawn(actually_send)
    coro.event_loop()
    rv = result[0].split('\r\n\r\n', 1)
    if len(rv) != 2:
        rv = ('', '')
    return rv
Esempio n. 2
0
def run(here, log, loglevel, logdir, **kwargs):
    heart = Heartbeat(
        1.2, # every 1.2 seconds
        log = log,
        )
    heart.set_log_level(loglevel)
    heart.start()

    if 'backport' in here:
        back = backdoor.BackDoorServer(
            args = (here['backport'],),
            log  = log, 
            )
        back.set_log_level(loglevel)
        back.start()

    def shutdown_handler(signum, frame):
        heart.shutdown()
        back.shutdown()

    signal.signal(signal.SIGUSR2, shutdown_handler)

    try:
        coro.event_loop()
    except KeyboardInterrupt:
        pass

    return None
Esempio n. 3
0
def main():
    notif = coroutines.Notifier(args=(NOTIFIERS,), kwargs={'port': 7000})
    notif.start()

    handler = Handler()

    notif.rpc_slice(ECHO, (0, 0), 'execute', handler)

    notif.set_log_level(logging.INFO)

    signal.signal(signal.SIGINT, lambda signum, frame: notif.shutdown())

    coro.event_loop()
Esempio n. 4
0
def main():
    pynotify.init('notifier-pynotify')

    notifier = coroutines.Notifier(args=(NOTIFIERS,), kwargs={'port': 7000})
    notifier.start()

    handler = Handler()

    notifier.subscribe(GUI_NOTIFY, (0, 0), CMD_NAME, handler)
    notifier.set_log_level(logging.INFO)

    signal.signal(signal.SIGINT, lambda signum, frame: notifier.shutdown())

    coro.event_loop()
Esempio n. 5
0
def run(here, log, loglevel, logdir, **kwargs):
    eserv = EchoServer(addr = ('', ECHO_PORT))
    eserv.start()

    def shutdown_handler(signum, frame):
        eserv.shutdown()

    signal.signal(signal.SIGUSR2, shutdown_handler)

    try:
        coro.event_loop()
    except KeyboardInterrupt:
        pass

    return None
Esempio n. 6
0
def main():
    notif = coroutines.Notifier(args=(NOTIFIERS,), kwargs={'port': 7000})
    notif.start()

    server = EchoServer(
            100,
            notifier=notif,
            bounds={'mask': 0, 'value': 0},
            loglevel=logging.INFO)

    def shutdown(signum, frame):
        coro.spawn(lambda: server.drain() and notif.shutdown())
    signal.signal(signal.SIGINT, shutdown)

    coro.event_loop()
Esempio n. 7
0
def run(here, log, loglevel, logdir, **kwargs):
    heart = Heartbeat(1.2, log=log)  # every 1.2 seconds
    heart.set_log_level(loglevel)
    heart.start()

    if "backport" in here:
        back = backdoor.BackDoorServer(args=(here["backport"],), log=log)
        back.set_log_level(loglevel)
        back.start()

    def shutdown_handler(signum, frame):
        heart.shutdown()
        back.shutdown()

    signal.signal(signal.SIGUSR2, shutdown_handler)

    try:
        coro.event_loop()
    except KeyboardInterrupt:
        pass

    return None
Esempio n. 8
0
def sendreq(site, bytes):
    result = []

    def actually_send():
        socket = FakeSocket(bytes)
        waiter = coro.coroutine_cond()
        server = FakeServer(waiter)
        log = coro.coroutine_logger("tests")
        output = cStringIO.StringIO()
        log.addHandler(logging.StreamHandler(output))
        http = corohttpd.HttpProtocol(args=(socket, ("<fake>", 0), server, [site]), log=log)
        http.start()
        waiter.wait(0.01)
        if socket.pushed.startswith("HTTP/1.1 500"):
            output.seek(0)
            print output.read()
        result.append(socket.pushed)

    coro.spawn(actually_send)
    coro.event_loop()
    rv = result[0].split("\r\n\r\n", 1)
    if len(rv) != 2:
        rv = ("", "")
    return rv