本文整理汇总了Python中cattle.Config.max_dropped_ping方法的典型用法代码示例。如果您正苦于以下问题:Python Config.max_dropped_ping方法的具体用法?Python Config.max_dropped_ping怎么用?Python Config.max_dropped_ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cattle.Config
的用法示例。
在下文中一共展示了Config.max_dropped_ping方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_message
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import max_dropped_ping [as 别名]
def on_message(ws, message):
line = message.strip()
try:
ping = '"ping' in line
if len(line) > 0:
# TODO Need a better approach here
if ping:
self._ping_queue.put(line, block=False)
drops['ping_drop'] = 0
else:
self._queue.put(line, block=False)
except Full:
log.info("Dropping request %s" % line)
drops['drop_count'] += 1
drop_max = Config.max_dropped_requests()
drop_type = 'overall'
drop_test = drops['drop_count']
if ping:
drops['ping_drop'] += 1
drop_type = 'ping'
drop_test = drops['ping_drop']
drop_max = Config.max_dropped_ping()
if drop_test > drop_max:
log.error('Max of [%s] dropped [%s] requests exceeded',
drop_max, drop_type)
ws.close()
if not _should_run(ppid):
log.info("Parent process has died or stamp changed,"
" exiting")
ws.close()
示例2: _run
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import max_dropped_ping [as 别名]
def _run(self, events):
ppid = os.environ.get("AGENT_PARENT_PID")
headers = {}
args = {
"data": _data(events, self._agent_id),
"stream": True,
"headers": headers,
"timeout": Config.event_read_timeout()
}
if self._auth is not None:
if isinstance(self._auth, basestring):
headers["Authorization", self._auth]
else:
args["auth"] = self._auth
try:
drop_count = 0
ping_drop = 0
r = requests.post(self._url, **args)
if r.status_code != 201:
raise Exception(r.text)
self._start_children()
for line in r.iter_lines(chunk_size=1):
try:
ping = '"ping' in line
if len(line) > 0:
# TODO Need a better approach here
if ping:
self._ping_queue.put(line, block=False)
ping_drop = 0
else:
self._queue.put(line, block=False)
except Full:
log.info("Dropping request %s" % line)
drop_count += 1
max = Config.max_dropped_requests()
if ping:
ping_drop += 1
max = Config.max_dropped_ping()
if drop_count > max:
log.error('Max dropped requests [%s] exceeded', max)
break
if not _should_run(ppid):
log.info("Parent process has died or stamp changed,"
" exiting")
break
finally:
for child in self._children:
if hasattr(child, "terminate"):
try:
child.terminate()
except:
pass
sys.exit(0)