本文整理汇总了Python中tornado.log.app_log.debug方法的典型用法代码示例。如果您正苦于以下问题:Python app_log.debug方法的具体用法?Python app_log.debug怎么用?Python app_log.debug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.log.app_log
的用法示例。
在下文中一共展示了app_log.debug方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: headers_received
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> Optional[Awaitable[None]]:
assert isinstance(start_line, httputil.RequestStartLine)
request = httputil.HTTPServerRequest(
connection=self.request_conn,
server_connection=self.server_conn,
start_line=start_line,
headers=headers,
)
self.delegate = self.router.find_handler(request)
if self.delegate is None:
app_log.debug(
"Delegate for %s %s request not found",
start_line.method,
start_line.path,
)
self.delegate = _DefaultMessageDelegate(self.request_conn)
return self.delegate.headers_received(start_line, headers)
示例2: manually_kill_server
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def manually_kill_server(user_name):
# Get our AWS server db's instance for the user
try:
server = Server.get_server(user_name)
app_log.debug("Checking server for %s manually..." % user_name)
except Server.DoesNotExist:
# it is not necessarily the case that a server will exist, we return early if that is the case.
app_log.warn("There is no matching, allocated server for user %s" % user_name)
return
# get server instance information
resource = yield retry(boto3.resource, "ec2", region_name=SERVER_PARAMS["REGION"])
instance = yield retry(resource.Instance, server.server_id)
# instance object is lazy, run this to get full info...
yield retry(instance.load)
#stop server if state is running (possible states are stopped, stopping, pending, shutting-down, terminated, and running)
if instance.state["Name"] == "running":
retry(instance.stop)
app_log.info("manually killed server for user %s" % user_name)
else:
app_log.debug("server state for user %s is %s, no action taken" % (user_name, instance.state["Name"]))
示例3: headers_received
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def headers_received(self, start_line, headers):
request = httputil.HTTPServerRequest(
connection=self.request_conn,
server_connection=self.server_conn,
start_line=start_line, headers=headers)
self.delegate = self.router.find_handler(request)
if self.delegate is None:
app_log.debug("Delegate for %s %s request not found",
start_line.method, start_line.path)
self.delegate = _DefaultMessageDelegate(self.request_conn)
return self.delegate.headers_received(start_line, headers)
示例4: check_password
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def check_password(self, password):
password = b(password)
pw_hash = b(self)
hashed = b(hashpw(password, pw_hash))
log.debug("Password hashed=%r self=%r", hashed, self)
return hashed == pw_hash
示例5: update_stats
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def update_stats(stats):
"""Get updated stats for each host
If a host fails to reply,
assume it is is down and assign it zero availability and capacity
"""
http_client = AsyncHTTPClient()
futures = {}
for host in stats.keys():
app_log.debug("Checking stats on %s" % host)
req = HTTPRequest(host + '/stats')
futures[host] = http_client.fetch(req)
for host, f in futures.items():
try:
reply = yield f
data = json.loads(reply.body.decode('utf8'))
except Exception as e:
app_log.error("Failed to get stats for %s: %s", host, e)
if host in stats:
stats[host] = down_stats()
else:
app_log.debug("Got stats from %s: %s", host, data)
if host in stats:
stats[host] = data
示例6: cull_idle
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def cull_idle(url, api_token, timeout):
"""cull idle single-user servers"""
auth_header = {
'Authorization': 'token %s' % api_token
}
req = HTTPRequest(url=url + '/users',
headers=auth_header,
)
now = datetime.datetime.utcnow()
cull_limit = now - datetime.timedelta(seconds=timeout)
client = AsyncHTTPClient()
resp = yield client.fetch(req)
users = json.loads(resp.body.decode('utf8', 'replace'))
futures = []
for user in users:
last_activity = parse_date(user['last_activity'])
if user['server'] and last_activity < cull_limit:
app_log.info("Culling %s (inactive since %s)", user['name'], last_activity)
req = HTTPRequest(url=url + '/users/%s/server' % user['name'],
method='DELETE',
headers=auth_header,
)
futures.append((user['name'], client.fetch(req)))
elif user['server'] and last_activity > cull_limit:
app_log.debug("Not culling %s (active since %s)", user['name'], last_activity)
for (name, f) in futures:
yield f
app_log.debug("Finished culling %s", name)
示例7: handle_error
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def handle_error(self, ex: Exception) -> None:
if not isinstance(ex, (web.HTTPError, ExecutionError, GraphQLError)):
tb = "".join(traceback.format_exception(*sys.exc_info()))
app_log.error("Error: {0} {1}".format(ex, tb))
self.set_status(self.error_status(ex))
error_json = json_encode({"errors": self.error_format(ex)})
app_log.debug("error_json: %s", error_json)
self.write(error_json)
示例8: cull_idle
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def cull_idle(url, api_token, timeout):
#last valid activity timestame
cull_limit = datetime.datetime.utcnow() - datetime.timedelta(seconds=timeout)
#get user list
hub_api_authorization_header = { 'Authorization': 'token %s' % api_token}
users_request = HTTPRequest(url=url + '/users', headers=hub_api_authorization_header )
#run request tornado-asynchronously, extract user list (contains more information)
resp = yield AsyncHTTPClient().fetch(users_request)
all_users = json.loads(resp.body.decode('utf8', 'replace'))
#build a bunch of (asynchronous) HTTP request futures...
stop_notebook_futures = []
servers_to_check = []
dont_cull_these = set()
for user in all_users:
#extract last activity time, determine cullability of the server.
last_activity = parse_date(user['last_activity'])
should_cull = last_activity.replace(tzinfo=None) < cull_limit.replace(tzinfo=None)
user_name = user['name']
app_log.debug("checking %s, last activity: %s, server: %s" % (user_name, last_activity, user['server']) )
if not should_cull:
dont_cull_these.add(user_name)
#server should be culled:
if user['server'] and should_cull:
app_log.info("Culling %s (inactive since %s)", user_name, last_activity)
stop_user_request = HTTPRequest(url=url + '/users/%s/server' % user_name,
method='DELETE',
headers=hub_api_authorization_header )
stop_notebook_futures.append( (user_name, AsyncHTTPClient().fetch(stop_user_request)) )
#Server status is None, which means actual status needs to be checked.
if not user['server'] and should_cull:
servers_to_check.append(user_name)
#server should not be culled, just a log statement
if user['server'] and not should_cull:
app_log.info("Not culling %s (active since %s)", user['name'], last_activity)
# Cull notebooks using normal API.
for (user_name, cull_request) in stop_notebook_futures:
try:
yield cull_request #this line actually runs the api call to kill a server
except HTTPError:
#Due to a bug in Jupyterhub
app_log.error("Something went wrong culling %s, will be manually killing it.", user_name)
servers_to_check.append( user_name )
continue
app_log.info("Finished culling %s", user_name)
for user_name in servers_to_check:
if user_name not in dont_cull_these:
yield manually_kill_server(user_name)
示例9: cleanup_builds
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def cleanup_builds(cls, kube, namespace, max_age):
"""Delete stopped build pods and build pods that have aged out"""
builds = kube.list_namespaced_pod(
namespace=namespace,
label_selector='component=binderhub-build',
).items
phases = defaultdict(int)
app_log.debug("%i build pods", len(builds))
now = datetime.datetime.now(tz=datetime.timezone.utc)
start_cutoff = now - datetime.timedelta(seconds=max_age)
deleted = 0
for build in builds:
phase = build.status.phase
phases[phase] += 1
annotations = build.metadata.annotations or {}
repo = annotations.get("binder-repo", "unknown")
delete = False
if build.status.phase in {'Failed', 'Succeeded', 'Evicted'}:
# log Deleting Failed build build-image-...
# print(build.metadata)
app_log.info(
"Deleting %s build %s (repo=%s)",
build.status.phase,
build.metadata.name,
repo,
)
delete = True
else:
# check age
started = build.status.start_time
if max_age and started and started < start_cutoff:
app_log.info(
"Deleting long-running build %s (repo=%s)",
build.metadata.name,
repo,
)
delete = True
if delete:
deleted += 1
try:
kube.delete_namespaced_pod(
name=build.metadata.name,
namespace=namespace,
body=client.V1DeleteOptions(grace_period_seconds=0))
except client.rest.ApiException as e:
if e.status == 404:
# Is ok, someone else has already deleted it
pass
else:
raise
if deleted:
app_log.info("Deleted %i/%i build pods", deleted, len(builds))
app_log.debug("Build phase summary: %s", json.dumps(phases, sort_keys=True, indent=1))
示例10: _check_hub_authorization
# 需要导入模块: from tornado.log import app_log [as 别名]
# 或者: from tornado.log.app_log import debug [as 别名]
def _check_hub_authorization(self, url, cache_key=None, use_cache=True):
"""Identify a user with the Hub
Args:
url (str): The API URL to check the Hub for authorization
(e.g. http://127.0.0.1:8081/hub/api/authorizations/token/abc-def)
cache_key (str): The key for checking the cache
use_cache (bool): Specify use_cache=False to skip cached cookie values (default: True)
Returns:
user_model (dict): The user model, if a user is identified, None if authentication fails.
Raises an HTTPError if the request failed for a reason other than no such user.
"""
if use_cache:
if cache_key is None:
raise ValueError("cache_key is required when using cache")
# check for a cached reply, so we don't check with the Hub if we don't have to
cached = self.cache.get(cache_key)
if cached is not None:
return cached
try:
r = requests.get(url,
headers = {
'Authorization' : 'token %s' % self.api_token,
},
)
except requests.ConnectionError:
msg = "Failed to connect to Hub API at %r." % self.api_url
msg += " Is the Hub accessible at this URL (from host: %s)?" % socket.gethostname()
if '127.0.0.1' in self.api_url:
msg += " Make sure to set c.JupyterHub.hub_ip to an IP accessible to" + \
" single-user servers if the servers are not on the same host as the Hub."
raise HTTPError(500, msg)
data = None
if r.status_code == 404:
app_log.warning("No Hub user identified for request")
elif r.status_code == 403:
app_log.error("I don't have permission to check authorization with JupyterHub, my auth token may have expired: [%i] %s", r.status_code, r.reason)
raise HTTPError(500, "Permission failure checking authorization, I may need a new token")
elif r.status_code >= 500:
app_log.error("Upstream failure verifying auth token: [%i] %s", r.status_code, r.reason)
raise HTTPError(502, "Failed to check authorization (upstream problem)")
elif r.status_code >= 400:
app_log.warning("Failed to check authorization: [%i] %s", r.status_code, r.reason)
raise HTTPError(500, "Failed to check authorization")
else:
data = r.json()
app_log.debug("Received request from Hub user %s", data)
if use_cache:
# cache result
self.cache[cache_key] = data
return data