spaCy 在使用 zappa 部署到 AWS Lambda 时抛出 OSError



将Python spaCy应用程序部署到AWS Lambda时,我在部署中收到以下错误(见下文(。为什么要使用 zappa 进行部署?zip 文件经过压缩后为 125MB,因此从 aws-cli 直接上传在空间上失败,并且传输到 S3 也会失败,因为未压缩的文件超过 250MB。

我的程序本身没有做任何多线程或多处理,它只使用 spaCy 2.0。我在EC2 AWS Linux t2.medium上构建并部署。从spaCy AWS Lambda函数获得往返答案的确切步骤是什么?

故障跟踪如下:

[1520570028387] Failed to find library...right filename?
[1520570029826] [Errno 38] Function not implemented: OSError
Traceback (most recent call last):
  File "/var/task/handler.py", line 509, in lambda_handler
  return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 237, in lambda_handler
  handler = cls()
  File "/var/task/handler.py", line 129, in __init__
  self.app_module = importlib.import_module(self.settings.APP_MODULE)
  File "/var/lang/lib/python3.6/importlib/__init__.py", line 126, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/tmp/spaciness/front.py", line 1, in <module>
  import spacy
  File "/tmp/spaciness/spacy/__init__.py", line 4, in <module>
  from .cli.info import info as cli_info
  File "/tmp/spaciness/spacy/cli/__init__.py", line 1, in <module>
  from .download import download
  File "/tmp/spaciness/spacy/cli/download.py", line 10, in <module>
  from .link import link
  File "/tmp/spaciness/spacy/cli/link.py", line 7, in <module>
  from ..compat import symlink_to, path2str
  File "/tmp/spaciness/spacy/compat.py", line 11, in <module>
  from thinc.neural.util import copy_array
  File "/tmp/spaciness/thinc/neural/__init__.py", line 1, in <module>
  from ._classes.model import Model
  File "/tmp/spaciness/thinc/neural/_classes/model.py", line 12, in <module>
  from ..train import Trainer
  File "/tmp/spaciness/thinc/neural/train.py", line 7, in <module>
  from tqdm import tqdm
  File "/tmp/spaciness/tqdm/__init__.py", line 1, in <module>
  from ._tqdm import tqdm
  File "/tmp/spaciness/tqdm/_tqdm.py", line 53, in <module>
  mp_lock = mp.Lock()  # multiprocessing lock
  File "/var/lang/lib/python3.6/multiprocessing/context.py", line 67, in Lock
  return Lock(ctx=self.get_context())
  File "/var/lang/lib/python3.6/multiprocessing/synchronize.py", line 163, in __init__
  SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
  File "/var/lang/lib/python3.6/multiprocessing/synchronize.py", line 60, in __init__
  unlink_now)
OSError: [Errno 38] Function not implemented

我可以通过以下步骤解决问题:

  1. 增加 zappa_settings.json 中 lambda 函数的内存大小:

    { "开发":{

        "memory_size": 3008,
    }
    

    }

  2. 我不得不使用较新版本的 tqdm。默认情况下,它是版本4.19,其中存在以下问题,如下所述:https://github.com/tqdm/tqdm/issues/466

所描述的问题已在较新版本中修复。它只是将tqdm添加到我的requirements.txt并执行软件包的 pip 升级:

pip install -U tqdm

当我执行zappa deploy dev时,我现在收到以下消息:

(tqdm 4.32.1 (/var/task/ve/lib/python3.6/site-packages(, Requirements.parse('tqdm==4.19.1'(, {'zappa'}(

TQDM 4.19.1 是 Zappa 的默认版本,TQDM 4.32.1 是包含修复程序的新版本。

相关内容

  • 没有找到相关文章

最新更新