小编ado*_*wds的帖子

可扩展的国际地理编码解决方案

我们希望网站支持国际地理编码.我们对使用限制和/或限制请求的API持谨慎态度,这可能会随着服务量的增加而使我们的裤子缩短.Facebook等现代网站如何实施地理编码?是否有工具为全世界实施准确的内部可扩展地理编码解决方案?

javascript geocoding web-applications

12
推荐指数
1
解决办法
356
查看次数

使用Python的Fabric库进行嵌套调用"execute"

Python的Fabric提供了fab使用该execute函数调用实用程序外部的结构函数的功能.当execute在使用execute调用的另一个函数内调用函数时,会出现上下文问题.当调用内部执行时,Fabric丢失外部执行的上下文,并且永远不会恢复它.例如:

env.roledefs = {
    'webservers': ['web1','web2'],
    'load_balancer': ['lb1']
}

@roles('webserver')
def deploy_code():
    #ship over tar.gz of code to unpack.
    ...
    execute(remove_webserver_from_load_balancer, sHost=env.host_string)
    ...
    #shutdown webserver, unpack files, and restart web server
    ...
    execute(add_webserver_to_load_balancer, sHost=env.host_string)

@roles('load_balancer')
def remove_webserver_from_load_balancer(sHost=None):
   ssh("remove_host %s" % sHost)

execute(deploy_code)
Run Code Online (Sandbox Code Playgroud)

在第一次调用之后execute,Fabric完全丢失其上下文并执行deploy_code函数内的所有其他命令host_string='lb1'而不是'web1'. 我怎么能记住呢?

我想出了这个黑客,但我觉得它可能在未来的版本中破解:

 with settings(**env):
     execute(remove_webserver_from_load_balancer, sHost=env.host_string)
Run Code Online (Sandbox Code Playgroud)

这有效地保存了所有状态并在调用后恢复它,但看起来像是无意中使用了该函数.有没有更好的方法告诉Fabric它在嵌套执行中并使用设置堆栈或等效方法来记住状态?

谢谢!

python fabric

9
推荐指数
1
解决办法
4375
查看次数

标签 统计

fabric ×1

geocoding ×1

javascript ×1

python ×1

web-applications ×1