Ejemplo n.º 1
0
Archivo: cli.py Proyecto: dowski/aspen
def main(argv=None):
    try:
        configuration = Configuration(argv)
        configuration.app = app = Application()
        website = Website(configuration)
        configuration.website = website  # to support re-handling, especially
        website = configuration.hooks.run('startup', website)

        # change current working directory
        os.chdir(configuration.root)

        if configuration.conf.aspen.no('changes_kill'):
            # restart for template files too;
            # TODO can't we just invalidate the simplate cache for these?
            dot_aspen = join(configuration.root, '.aspen')
            for root, dirs, files in os.walk(dot_aspen):
                for filename in files:
                    restarter.add(join(root, filename))

            app.add_loop(Loop(restarter.loop))

        port = configuration.address[1]
        app.add_service(Service(http.HttpServer(website), port))

        log.warn("Greetings, program! Welcome to port %d." % port)
        app.run()

    except KeyboardInterrupt, SystemExit:
        configuration.hooks.run('shutdown', website)
Ejemplo n.º 2
0
def test_loop_keep_alive_normal_death():
    v = [0]

    def l():
        v[0] += 1

    def p():
        sleep(0.9)
        WVPASS(v[0] > 1)
        a.halt()

    a = Application()
    a.add_loop(Loop(l), keep_alive=True)
    a.add_loop(Loop(p))
    a.run()
Ejemplo n.º 3
0
def test_loop_keep_alive_exception():
    v = [0]

    def l():
        v[0] += 1
        a = b  # exception!

    def p():
        sleep(0.9)
        WVPASS(v[0] > 1)
        a.halt()

    a = Application()
    a.add_loop(Loop(l), keep_alive=True)
    a.add_loop(Loop(p))
    a.run()
Ejemplo n.º 4
0
def main():
    app = Application()
    app.add_loop(Loop(santa))

    elf_do = "meets in study"
    for i in xrange(10):
        app.add_loop(Loop(actor("Elf %d" % i, 'elf', elf_group, elf_do, 3, 3)))

    deer_do = "delivers toys"
    for name in [
            'Dasher', 'Dancer', 'Prancer', 
            'Vixen', 'Comet', 'Cupid', 
            'Donner', 'Blitzen', 'Rudolph',
            ]:
        app.add_loop(Loop(actor(name, 'deer', deer_group, deer_do, 9, 9)))

    app.run()
Ejemplo n.º 5
0
                        resp.append(receive(l))
                        until_eol()  # noop
                elif hl[0] == ':':
                    resp.append(int(hl[1:]))
            return resp
        elif c == ':':
            return int(fl[1:])
        elif c == '-':
            e_message = fl[1:]
            raise RedisError(e_message)


if __name__ == '__main__':
    from diesel import Application, Loop

    a = Application()

    def do_set():
        r = RedisClient()

        r.select(11)
        r.flushdb()

        print '--BASIC--'
        assert r.get('newdb') == None
        r.set('newdb', '1')

        r.set('foo3', 'bar')
        assert r.exists('foo3')
        r.delete('foo3')
        assert not r.exists('foo3')
Ejemplo n.º 6
0
import time
from diesel import Application, Service, Client, Loop, until, call, response

def handle_echo(remote_addr):
    while True:
        message = yield until('\r\n')
        yield "you said: %s" % message

class EchoClient(Client):
    @call
    def echo(self, message):
        yield message + '\r\n'
        back = yield until("\r\n")
        yield response(back)

app = Application()

def do_echos():
    client = EchoClient()
    yield client.connect('localhost', 8000)
    t = time.time()
    for x in xrange(5000):
        msg = "hello, world #%s!" % x
        echo_result = yield client.echo(msg)
        assert echo_result.strip() == "you said: %s" % msg
    print '5000 loops in %.2fs' % (time.time() - t)
    app.halt()

app.add_service(Service(handle_echo, port=8000))
app.add_loop(Loop(do_echos))
app.run()
Ejemplo n.º 7
0
 def setup_method(self, *args):
     self._app = Application(allow_app_replacement=True)
     self._trigger = TestTrigger()