当前位置: 首页>>代码示例>>Python>>正文


Python diesel.Application类代码示例

本文整理汇总了Python中diesel.Application的典型用法代码示例。如果您正苦于以下问题:Python Application类的具体用法?Python Application怎么用?Python Application使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

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()
开发者ID:1angxi,项目名称:diesel,代码行数:17,代码来源:santa.py

示例2: DieselTest

class DieselTest(object):
    def setup_method(self, *args):
        self._app = Application(allow_app_replacement=True)
        self._trigger = TestTrigger()

    # XXX py.test magic args?
    def prepare_test(self):
        return self._app, self._trigger.touch, TestAccumulator()

    def run_test(self, count=1, timeout=10):
        def trigger_thread():
            self._trigger.wait(timeout, count)
            try:
                self._app.halt()
            except app.ApplicationEnd:
                # XXX Does halt have to raise this? Should we do anything but
                # pass?
                pass
            self._app.hub.wake_from_other_thread()

        thread.start_new_thread(trigger_thread, ())
        self._app.run()
        if self._trigger.timed_out:
            raise TestTimeout()

    def teardown_method(self, *args):
        try:
            self._app.halt()
        except app.ApplicationEnd:
            # This is always raised?
            pass
        self._app = self._trigger = None
开发者ID:dowski,项目名称:aspen,代码行数:32,代码来源:tests.py

示例3: test_loop_keep_alive_normal_death

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()
开发者ID:timdoug,项目名称:diesel,代码行数:14,代码来源:diesel_test_basic_fork.py

示例4: test_loop_keep_alive_exception

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()
开发者ID:timdoug,项目名称:diesel,代码行数:15,代码来源:diesel_test_basic_fork.py

示例5: DieselTest

class DieselTest(object):
    def setup_method(self, *args):
        self._app = Application(allow_app_replacement=True)
        self._trigger = TestTrigger()

    # XXX py.test magic args?
    def prepare_test(self):
        return self._app, self._trigger.touch, TestAccumulator()

    def run_test(self, count=1, timeout=10):
        def trigger_thread():
            self._trigger.wait(timeout, count)
            self._app.halt()
            self._app.hub.wake_from_other_thread()
            
        thread.start_new_thread(trigger_thread, ())
        self._app.run()
        if self._trigger.timed_out:
            raise TestTimeout()

    def teardown_method(self, *args):
        self._app.halt()
        self._app = self._trigger = None
开发者ID:viraptor,项目名称:diesel,代码行数:23,代码来源:tests.py

示例6: restart

from diesel import Application, Loop, sleep
import time

def restart():
    print "I should restart"
    a = b

a = Application()
a.add_loop(Loop(restart), keep_alive=True)
a.run()
开发者ID:1angxi,项目名称:diesel,代码行数:10,代码来源:keep_alive.py

示例7: handle_echo

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))
开发者ID:Bobberino,项目名称:musings,代码行数:30,代码来源:diesel_test.py

示例8: free_loop

def free_loop():
    global free
    free += 1
    sleep(random.random())
    free -= 1
    print "FREE", free


def sync_loop():
    global sync
    id = random.random()
    with synchronized():
        sync += 1
        sleep(random.random())
        sync -= 1
        print "SYNC", sync


def manage():
    sleep(10)
    a.halt()


a = Application()
for l in (free_loop, sync_loop):
    for x in xrange(10):
        a.add_loop(Loop(l))
a.add_loop(Loop(manage))
a.run()
开发者ID:schmichael,项目名称:diesel,代码行数:29,代码来源:synchronized.py

示例9: setup_method

 def setup_method(self, *args):
     self._app = Application(allow_app_replacement=True)
     self._trigger = TestTrigger()
开发者ID:dowski,项目名称:aspen,代码行数:3,代码来源:tests.py

示例10: __init__

 def __init__(self, wsgi_callable, port=80, iface=''):
     Application.__init__(self)
     self.port = port
     self.wsgi_callable = wsgi_callable
     http_service = Service(HttpServer(WSGIRequestHandler(wsgi_callable, port)), port, iface)
     self.add_service(http_service)
开发者ID:timdoug,项目名称:diesel,代码行数:6,代码来源:wsgi.py

示例11: web_handler

<input type="text" size="40" id="the-i" /> <input type="button" value="Update Message" onclick="push(); return false" />

</body>
</html>
''' % LOCATION

def web_handler(req):
    heads = HttpHeaders()
    heads.add('Content-Length', len(content))
    heads.add('Content-Type', 'text/html')

    return http_response(req, 200, heads, content)

import time

def socket_handler(inq, outq):
    message = "hello, there!"
    while True:
        try:
            v = inq.get(timeout=0.5)
        except QueueTimeout:
            pass
        else:
            message = v['message']
                        
        outq.put(WSD(message=message, time=time.time()))

a = Application()
a.add_service(Service(WebSocketServer(web_handler, socket_handler, LOCATION), 8091))
a.run()
开发者ID:dowski,项目名称:aspen,代码行数:30,代码来源:ws.py

示例12: EchoClient

        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)

    return _loop


def echo_self_loop(n):
    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)

    return _loop


a = Application()
log = log.sublog("echo-client", log.info)

for x in xrange(5):
    a.add_loop(Loop(echo_loop(x)))
for x in xrange(5):
    a.add_loop(Loop(echo_self_loop(x)))
a.run()
开发者ID:viraptor,项目名称:diesel,代码行数:30,代码来源:echo_client.py

示例13: until_eol

                    else:
                        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.set('foo3', 'bar')
        assert r.exists('foo3')
        r.delete('foo3')
        assert not r.exists('foo3')

        for x in xrange(5000):
            r.set('foo', 'bar')

        print (r.get('foo'))
        print (r.get('foo2'))
        print (r.exists('foo'))
开发者ID:viraptor,项目名称:diesel,代码行数:31,代码来源:redis.py

示例14: delay_echo_server

# vim:ts=4:sw=4:expandtab
'''Non blocking memcache get/set.
'''
from diesel import Application, Service
from diesel.protocols.memcache import MemCacheClient
from diesel.protocols import http
from diesel import log

def delay_echo_server(addr):
    # default to 127.0.0.1:11211
    m = MemCacheClient('localhost')
    value = m.get('mykey')
    values = m.get_multi(['mykey', 'mykey1', 'mykey2'])
    
    return http.Response("value from multi_get : %s and get : %s"%(str(values), str(value)))
    #return http.Response("value from memcache key : %s key1 : %s and key 2 : %s"%(str(value), str(value1), str(value2)))

app = Application()
app.add_service(Service(http.HttpServer(delay_echo_server), 8000))
app.run()
开发者ID:pranjal5215,项目名称:diesel,代码行数:20,代码来源:memcache_get.py

示例15: blocker

# vim:ts=4:sw=4:expandtab
'''Example of deferring blocking calls to threads
'''
from diesel import Application, Loop, log, thread
import time

def blocker():
    x = 1
    while True:
        def f():
            time.sleep(1)
        thread(f)
        print 'yo!', time.time()

a = Application()
a.add_loop(Loop(blocker))
a.add_loop(Loop(blocker))
a.run()
开发者ID:dowski,项目名称:aspen,代码行数:18,代码来源:thread.py


注:本文中的diesel.Application类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。