Exemple #1
0
def main(args, global_state):
    global G

    G = global_state
    G.args = args

    if args.testnet:
        network.goto_testnet()

    if args.logfile:
        logger = coro.log.asn1.Logger(open(args.logfile, 'ab'))
    else:
        logger = coro.log.StderrLogger()

    coro.log.set_logger(logger)
    coro.log.redirect_stderr()

    if args.daemon:
        if not args.logfile:
            raise ValueError("--daemon without --logfile")
        else:
            daemonize()
            open('/var/run/caesure.pid', 'wb').write('%d\n' % os.getpid())

    coro.set_exception_notifier(exception_notifier)
    LOG('caesure', 'starting')

    coro.spawn(main1, args, G)

    try:
        coro.event_loop()
    except:
        LOG.exc()
    finally:
        LOG('caesure', 'stopping')
Exemple #2
0
def main(verbose=0):
    global exitval, msg
    default_exitval = exitval
    default_msg = msg
    reports = []
    failures = 0

    # 3.0 is a multiple of 1.0, which timing allows a latent interrupt.
    for sleep_val in [2.5, 3.0]:
        coro.spawn(tripwire, sleep_val)
        coro.event_loop()
        reports.append((sleep_val, msg, exitval))
        if exitval != 0:
            failures += 1

        # reset values:
        coro._exit = 0
        exitval = default_exitval
        msg = default_msg

    if failures:
        if verbose:
            print "%d failures" % (failures, )
            for sleep_val, msg, exitval in reports:
                print "sleep val %s: %s" % (sleep_val, msg)

        sys.exit(1)
    else:
        if verbose:
            print "All tests passed."
        sys.exit(0)
def main(verbose=0):
    global exitval, msg
    default_exitval = exitval
    default_msg = msg
    reports = []
    failures = 0

    # 3.0 is a multiple of 1.0, which timing allows a latent interrupt.
    for sleep_val in [2.5, 3.0]:
        coro.spawn (tripwire, sleep_val)
        coro.event_loop ()
        reports.append ((sleep_val, msg, exitval))
        if exitval != 0:
            failures += 1

        # reset values:
        coro._exit = 0
        exitval = default_exitval
        msg = default_msg

    if failures:
        if verbose:
            print "%d failures" % (failures,)
            for sleep_val, msg, exitval in reports:
                print "sleep val %s: %s" % (sleep_val, msg)

        sys.exit (1)
    else:
        if verbose:
            print "All tests passed."
        sys.exit (0)
Exemple #4
0
def main (args, global_state):
    global G

    G = global_state
    G.args = args

    if args.testnet:
        network.goto_testnet()

    if args.logfile:
        logger = coro.log.asn1.Logger (open (args.logfile, 'ab'))
    else:
        logger = coro.log.StderrLogger()

    coro.log.set_logger (logger)
    coro.log.redirect_stderr()

    if args.daemon:
        if not args.logfile:
            raise ValueError ("--daemon without --logfile")
        else:
            daemonize()
            open('/var/run/caesure.pid', 'wb').write ('%d\n' % os.getpid())

    coro.set_exception_notifier (exception_notifier)
    LOG ('caesure', 'starting')

    coro.spawn (main1, args, G)

    try:
        coro.event_loop()
    except:
        LOG.exc()
    finally:
        LOG ('caesure', 'stopping')
Exemple #5
0
    def test_coro_main(self):
        coro.set_print_exit_string(None)

        for x in range(4):
            try:
                coro.spawn(exit_coro)
                coro.event_loop()
            except SystemExit:
                pass
    def test_coro_main(self):
        coro.set_print_exit_string(None)

        for x in range(4):
            try:
                coro.spawn(exit_coro)
                coro.event_loop()
            except SystemExit:
                pass
Exemple #7
0
def run_tests():
    global main_thread
    coro.install_signal_handlers = 0
    coro.signal_handler.register(signal.SIGTERM, sigterm_handler)
    coro.signal_handler.register(signal.SIGINT, sigterm_handler)
    coro.set_exception_notifier(exception_notifier)
    main_thread = coro.spawn(main)
    coro.set_print_exit_string(False)
    coro.event_loop()
    sys.exit(exit_code)
Exemple #8
0
def run_tests():
    global main_thread
    coro.install_signal_handlers = 0
    coro.signal_handler.register (signal.SIGTERM, sigterm_handler)
    coro.signal_handler.register (signal.SIGINT, sigterm_handler)
    coro.set_exception_notifier(exception_notifier)
    main_thread = coro.spawn(main)
    coro.set_print_exit_string(False)
    coro.event_loop()
    sys.exit(exit_code)
Exemple #9
0
def serve(address, wsgiapp, access_log='', error_log=None):
    kwargs = {}
    if error_log:
        handler = logging.handlers.RotatingFileHandler(
            filename or 'log', 'a', corohttpd.ACCESS_LOG_SIZE_MAX,
            corohttpd.ACCESS_LOG_COUNT_MAX)
        handler.setFormatter(logging.Formatter('%(message)s'))
        kwargs['log'] = logging.Logger('error')
        kwargs['log'].addHandler(handler)

    server = corohttpd.HttpServer(args=(address, access_log), **kwargs)
    server.push_handler(WSGIAppHandler(wsgiapp))
    server.start()
    coro.event_loop()
Exemple #10
0
def run(url, log, loglevel):
    #
    # turn on curl emulation
    emulate()
    #
    # webserver and handler
    fetch = CurlFetch(log = log, args = (url,))
    fetch.set_log_level(loglevel)
    fetch.start()
    #
    # primary event loop.
    coro.event_loop()
    #
    # never reached...
    return None
Exemple #11
0
def run(url, log, loglevel):
	#
	# turn on curl emulation
	emulate()
	#
	# webserver and handler
	fetch = CurlFetch(log = log, args = (url,))
	fetch.set_log_level(loglevel)
	fetch.start()
	#
	# primary event loop.
	coro.event_loop()
	#
	# never reached...
	return None
Exemple #12
0
def main(argv, stdout, environ):
	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
Exemple #13
0
def serve(address, wsgiapp, access_log='', error_log=None):
    kwargs = {}
    if error_log:
        handler = logging.handlers.RotatingFileHandler(
                filename or 'log',
                'a',
                corohttpd.ACCESS_LOG_SIZE_MAX,
                corohttpd.ACCESS_LOG_COUNT_MAX)
        handler.setFormatter(logging.Formatter('%(message)s'))
        kwargs['log'] = logging.Logger('error')
        kwargs['log'].addHandler(handler)

    server = corohttpd.HttpServer(args=(address, access_log), **kwargs)
    server.push_handler(WSGIAppHandler(wsgiapp))
    server.start()
    coro.event_loop()
Exemple #14
0
                    the_timer.mark()
                    conn.send('ok\r\n')
                elif data == '!bench\r\n':
                    conn.send(
                        coro_bench.format_rusage(the_timer.bench()) +
                        '\r\n\000')
                elif data == '!stats\r\n':
                    conn.send('ok\r\n')
                    coro_bench.dump_stats()
                else:
                    conn.send('huh?\r\n')
            else:
                conn.send(data)


def serve(port):
    s = coro.make_socket(socket.AF_INET, socket.SOCK_STREAM)
    s.set_reuse_addr()
    s.bind(('', port))
    s.listen(8192)
    while 1:
        conn, addr = s.accept()
        coro.spawn(service_client, conn, addr)


if __name__ == '__main__':
    import backdoor
    coro.spawn(backdoor.serve)
    coro.spawn(serve, 9001)
    coro.event_loop(30.0)
Exemple #15
0
# -*- Mode: Python -*-
# companion to t0.py that uses amqp-shrapnel

import coro.amqp as amqp

# set this to see AMQP protocol-level info.
debug = False


def t2():
    global c
    c = amqp.client(('guest', 'guest'), '127.0.0.1')
    c.debug = debug
    c.go()  # i.e., connect...
    ch = c.channel()
    for i in range(10):
        ch.basic_publish('howdy %d' % (i, ),
                         exchange='ething',
                         routing_key='notification')
        coro.sleep_relative(5)
    coro.set_exit()


import coro
coro.spawn(t2)
coro.event_loop()
Exemple #16
0
                # turn the cursor back on...
                self.conn.send (CSI + '?25h')
        the_arena.listeners.remove (self)
        self.conn.close()
        self.fifo.push (None)

def status():
    while 1:
        coro.sleep_relative (2)
        coro.write_stderr ('%5d worms %5d threads\n' % (len(the_arena.worms), len(coro.all_threads)))

def serve():
    s = coro.tcp_sock()
    s.bind (('', 9001))
    s.listen (5)
    while 1:
        c, a = s.accept()
        t = terminal (c)
        the_arena.listeners.append (t)

if __name__ == '__main__':
    import coro.backdoor
    the_arena = arena()
    the_arena.populate (10)
    coro.spawn (status)
    coro.spawn (serve)
    coro.spawn (coro.backdoor.serve, unix_path='/tmp/xx.bd')
    #import coro.profiler
    #coro.profiler.go (coro.event_loop)
    coro.event_loop()
Exemple #17
0
def func1():
    print "func1 entering into wait."
    wait1.wait()
    print "func1 broke out of wait."

def func1_2():
    print "func1_2 entering into wait."
    wait1.wait()
    print "func1_2 broke out of wait."

def func2():
    print "func2 entering into wait."
    wait2.wait()
    print "func2 broke out of wait."

def func2_2():
    print "func2_2 entering into wait."
    wait2.wait()
    print "func2_2 broke out of wait."

def func3():
    wait1.wake_one()
    wait2.wake_all()

coro.spawn(func1)
coro.spawn(func1_2)
coro.spawn(func2)
coro.spawn(func2_2)
coro.spawn(func3)
coro.event_loop(30.0)
Exemple #18
0
def test (port='8021'):
    fs = ftp_server (dummy_authorizer(), port=int(port))
    #fs = ftp_server (unix_authorizer(), port=int(port))
    qlog.disable()
    coro.spawn (fs.run)
    coro.event_loop()