本文整理汇总了Python中cattle.Config.event_read_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python Config.event_read_timeout方法的具体用法?Python Config.event_read_timeout怎么用?Python Config.event_read_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cattle.Config
的用法示例。
在下文中一共展示了Config.event_read_timeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import event_read_timeout [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)
示例2: _run
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import event_read_timeout [as 别名]
def _run(self, events):
ppid = os.environ.get("AGENT_PARENT_PID")
headers = []
if self._auth is not None:
auth_header = 'Authorization: Basic ' + base64.b64encode(
('%s:%s' % self._auth).encode('latin1')).strip()
headers.append(auth_header)
subscribe_url = self._url.replace('http', 'ws')
query_string = _events_query_string(events, self._agent_id)
subscribe_url = subscribe_url + '?' + query_string
try:
drops = {
'drop_count': 0,
'ping_drop': 0,
}
self._start_children()
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()
def on_error(ws, error):
raise Exception('Received websocket error: [%s]', error)
def on_close(ws):
log.info('Websocket connection closed.')
def on_open(ws):
log.info('Websocket connection opened')
websocket.setdefaulttimeout(Config.event_read_timeout())
ws = websocket.WebSocketApp(subscribe_url,
header=headers,
on_message=on_message,
on_error=on_error,
on_close=on_close,
on_open=on_open)
ws.run_forever()
finally:
for child in self._children:
if hasattr(child, "terminate"):
try:
child.terminate()
except:
pass
sys.exit(0)