运行时上下文
runtime-context的Python项目详细描述
***************
运行时上下文代码块::shell
代码块::python
对于运行时上下文(dry_run=false):
do_something(1)for real
with runtime戋context(dry戋run=true):
do戋something(2)dry run
runtime戋context.dry戋run=false
do戋something(3)for real
with runtime戋context():
do戋something(4)#真正的
运行时上下文。干运行=真
做某事(5);干运行
代码块::python
import json
#类型:Union[你的应用程序,envbase]
@env.context戋u var戋set.listener(predicate=lambda name:name=='config戋file')
def reload戋u config():
如果不是env.config戋file:
返回
print('reloading config from{}.format(env.config戋file))
,打开(env.config戋file)为f:
config=json.load(f)
对于config.items()中的k,v:env.set(k,v)
with env():
assert env.dry_run为false
assert env.db_name为none
with env(dry_run=true):
assert env.dry_run为真
运行时上下文代码块::shell
代码块::python
对于运行时上下文(dry_run=false):
do_something(1)for real
with runtime戋context(dry戋run=true):
do戋something(2)dry run
runtime戋context.dry戋run=false
do戋something(3)for real
with runtime戋context():
do戋something(4)#真正的
运行时上下文。干运行=真
做某事(5);干运行
代码块::python
import json
#类型:Union[你的应用程序,envbase]
@env.context戋u var戋set.listener(predicate=lambda name:name=='config戋file')
def reload戋u config():
如果不是env.config戋file:
返回
print('reloading config from{}.format(env.config戋file))
,打开(env.config戋file)为f:
config=json.load(f)
对于config.items()中的k,v:env.set(k,v)
with env():
assert env.dry_run为false
assert env.db_name为none
with env(dry_run=true):
assert env.dry_run为真