本文整理汇总了Python中cocaine.services.Service.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python Service.disconnect方法的具体用法?Python Service.disconnect怎么用?Python Service.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocaine.services.Service
的用法示例。
在下文中一共展示了Service.disconnect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop_app
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def stop_app(self, appname):
succeed = list()
failed = list()
hosts_count = len(self.hosts)
for i, host in enumerate(self.hosts):
log.info("Stop %s at host %d/%d %s" % (appname, i, hosts_count, host))
nodeinstance = None
try:
nodeinstance = Service("node", blockingConnect=False)
yield nodeinstance.connect(host=host)
res = yield app.Stop(nodeinstance, appname).execute()
self.logcallback(str(res) + "\n")
except Exception as e:
item = "Unable to connect to node at host %s %s\n" % (host, e)
log.error(item)
self.logcallback(item)
failed.append(host)
else:
item = "App %s has been stoped successfully\n" % appname
log.info(item)
self.logcallback(item)
succeed.append(host)
finally:
if nodeinstance is not None:
nodeinstance.disconnect()
yield (succeed, failed)
示例2: process_synchronous
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def process_synchronous(self, cocaine_service_name, cocaine_method, data):
"""Synchronous Cocaine worker handling."""
self.log("In process_synchronous()")
service = Service(cocaine_service_name)
response = service.enqueue(cocaine_method, msgpack.dumps(data)).get()
service.disconnect()
self.log("process_synchronous() finished")
return response
示例3: process_asynchronous
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def process_asynchronous(self, cocaine_service_name, cocaine_method, data):
"""Run selected service and get all chunks as generator."""
self.log("In process_asynchronous()")
service = Service(cocaine_service_name)
chunks_g = service.enqueue(cocaine_method, msgpack.dumps(data))
yield chunks_g
service.disconnect()
self.log("process_asynchronous() finished")
示例4: start_async
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def start_async(self, login, power):
self.log("In start_async()")
service = Service("login")
login_response = yield service.enqueue("login", msgpack.dumps(login))
service.disconnect()
self.log("got login!")
if "error" in login_response:
self.log("Login '{0}' is invalid!".format(login))
self.write(login_response)
self.finish()
else:
self.log("Login '{0}' ok!".format(login))
self.process_powers("powers", "binary_powers", power)
self.log("Finished start_async()")
示例5: powers_8
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def powers_8(self):
self.log("In powers_8()")
service = Service("powers")
chunk = yield service.enqueue("binary_powers", msgpack.dumps(8))
chunks = [chunk]
try:
while True:
ch = yield
chunks.append(ch)
except ChokeEvent as err:
pass
self.powers_8_res = chunks
service.disconnect()
self.log("powers_8() finished")
示例6: process_powers
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def process_powers(self, cocaine_service_name, cocaine_method, data):
self.log("In process_powers()")
service = Service(cocaine_service_name)
chunk = yield service.enqueue(cocaine_method, msgpack.dumps(data))
if chunk:
try:
while True:
ch = yield
self.log(ch)
self.write_chunk("{0} ".format(ch))
except ChokeEvent as err:
pass
else:
self.write_chunk("no data!")
service.disconnect()
self.log("process_powers() finished")
self.finish()
示例7: app_info
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import disconnect [as 别名]
def app_info(task, response):
info = dict()
try:
name = task["appname"]
version = task["version"]
username = task["username"]
# todo: without version - search by mask? regex?
appname = appname_from_name_version(name, version)
if username:
# not admin - all apps
user_apps = yield app.List(storage).execute()
else:
user_apps = yield db.user_apps(username)
if appname not in user_apps:
raise ValueError("App %s doesn't exist" % appname)
hosts = yield hostdb.hosts()
for host in hosts:
appinstance = None
try:
appinstance = Service(appname, blockingConnect=False)
yield appinstance.connect(host=host)
info[host] = yield appinstance.info()
except Exception as err:
log.error("Unable to connect to app %s host %s" % (appname,
host))
finally:
if appinstance is not None:
appinstance.disconnect()
except KeyError as err:
response.error(-500, "Missing argument %s" % str(err))
except Exception as err:
log.error("Unknown error %s" % repr(err))
response.error(-100, "Unknown error %s" % repr(err))
else:
response.write(info)
finally:
response.close()