小编san*_*mar的帖子

我们如何在运行时分析 Flask API 的内存、CPU 负载?

我正在为我的 Flask 应用程序使用 python 3,该应用程序在端口 5000 中运行。它有一个示例 API。我需要在从 REST 或浏览器访问此 API 时分析内存、CPU 使用情况。

请帮助我找到更好的解决方案。

import logging
from flask import Flask, jsonify
from flask_cors import CORS

logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - "
                          "%(name)s:%(lineno)d [-] %(funcName)s- %(message)s")
logger.setLevel(logging.INFO)


app = Flask(__name__)
app.url_map.strict_slashes = False
CORS(app)


def health_check():
   return jsonify({"message": "success"})


app.add_url_rule(rule='/health', endpoint='health-check', 
    view_func=health_check, methods=['GET'])

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)
Run Code Online (Sandbox Code Playgroud)

memory-profiling cprofile flask python-3.x line-profiler

6
推荐指数
1
解决办法
7656
查看次数

使用 python 在 AWS S3 存储桶中搜索特定文件

我有 AWS S3 访问权限,并且存储桶内有近 300 个文件。我需要通过模式匹配或搜索从该存储桶下载单个文件,因为我不知道确切的文件名(假设文件以 .csv 格式结尾)。
这是我的示例代码,显示了存储桶内的所有文件

def s3connection(credentialsdict):
    """
    :param access_key: Access key for AWS to establish S3 connection
    :param secret_key: Secret key for AWS to establish S3 connection
    :param file_name: file name of the billing file(csv file)
    :param bucket_name: Name of the bucket which consists of billing files
    :return: status, billing_bucket, billing_key
    """
    os.environ['S3_USE_SIGV4'] = 'True'
    conn = S3Connection(credentialsdict["access_key"], credentialsdict["secret_key"], host='s3.amazonaws.com')
    billing_bucket = conn.get_bucket(credentialsdict["bucket_name"], validate=False)
    try:
        billing_bucket.get_location()
    except S3ResponseError as e:
        if e.status == 400 and …
Run Code Online (Sandbox Code Playgroud)

python amazon-s3 boto botocore boto3

3
推荐指数
1
解决办法
2万
查看次数

使用熊猫获取空单元格的行和列

我正在尝试获取包含空单元格的 xls 文件。我需要使用 Pandas 验证 xls 文件以获取行和列位置

这是excel表格

预期输出:

第 2 行第 2 列的值为空 [OR] 未找到 Account1 的租户 ID

python excel pandas data-handling pandas-groupby

3
推荐指数
1
解决办法
7326
查看次数