本文整理汇总了Python中diesel.Application.run方法的典型用法代码示例。如果您正苦于以下问题:Python Application.run方法的具体用法?Python Application.run怎么用?Python Application.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diesel.Application
的用法示例。
在下文中一共展示了Application.run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DieselTest
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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
示例2: test_loop_keep_alive_normal_death
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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()
示例3: test_loop_keep_alive_exception
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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()
示例4: main
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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()
示例5: DieselTest
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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
示例6: len
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
# vim:ts=4:sw=4:expandtab
'''The oh-so-canonical "Hello, World!" http server.
'''
from diesel import Application, Service
from diesel.protocols import http
# Pre-gen, since it's static..
content = "Hello, World!"
headers = http.HttpHeaders()
headers.add('Content-Length', len(content))
headers.add('Content-Type', 'text/plain')
def hello_http(req):
return http.http_response(req, 200, headers, content)
app = Application()
app.add_service(Service(http.HttpServer(hello_http), 8088))
app.run()
示例7: free_loop
# 需要导入模块: from diesel import Application [as 别名]
# 或者: from diesel.Application import run [as 别名]
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()