我在 AWS 中有一个相对简单的线性回归 lambda。调用该函数的每个实例,日志显示以下内容:
/opt/python/sklearn/externals/joblib/_multiprocessing_helpers.py:38: UserWarning: [Errno 38] Function not implemented. joblib will operate in serial mode
warnings.warn('%s. joblib will operate in serial mode' % (e,))
我怀疑这是由于 sklearn 在 lambda(即“无服务器”)上运行并试图根据 this question 确定它的多处理能力和 this GH issue .
我也从 GH 了解到,这不是一个“可修复”的问题,当在此硬件上部署这些依赖项时,它总是会发生。我得到了我的预期结果(即使我目前正在最大化默认的最小 lambda 内存 128mb)。
我的目标是控制警告,并知道是否有办法:
最佳答案
要捕获警告并防止将其传递到 cloudwatch 日志中,您可以按如下方式过滤警告。
import json
import warnings
warnings.filterwarnings('error')
try:
import sklearn
except Warning:
pass
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
article here ,特别是在最后,重新创建和过滤警告。
关于python-3.x - 我应该如何处理 AWS lambda 实现中的 joblib 多处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55577358/