Flask App,Gunicorn没有看到自定义类?

时间:2019-05-07 16:59:07

标签: flask gunicorn

我有一个flask应用程序,可以在Jupyter笔记本中以及本地计算机上的app.py中正常运行。但是,当我部署到云(渲染)时,我收到一个Gunicorn错误,提示它无法获取属性(我需要的自定义类)

我必须定义一些自定义类:

class SegLabelListCustom(SegmentationLabelList):
def open(self, fn): return open_mask(fn, div=True)

class SegItemListCustom(SegmentationItemList):
_label_cls = SegLabelListCustom

在打开保存的深度学习文件之前:

learn = load_learner(path, 'cell_export.pkl')

这在我的Jupyter笔记本中正常运行,并在本地运行app.py serve

但是,当我在使用Gunicorn的云中部署时,出现以下错误:

File "/opt/render/project/src/.venv/bin/gunicorn", line 10, in <module>
    sys.exit(run())
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 223, in run
    super(Application, self).run()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 60, in __init__
    self.setup(app)
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 120, in setup
    self.app.wsgi()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/opt/render/project/src/app.py", line 49, in <module>
    learn = load_learner(path, export_file_name)
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/fastai/basic_train.py", line 598, in load_learner
    state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/torch/serialization.py", line 387, in load
    return _load(f, map_location, pickle_module, **pickle_load_args)
  File "/opt/render/project/src/.venv/lib/python3.7/site-packages/torch/serialization.py", line 574, in _load
    result = unpickler.load()
AttributeError: Can't get attribute 'SegItemListCustom' on <module '__main__' from '/opt/render/project/src/.venv/bin/gunicorn'>

我不确定该如何解决或解决此问题。

0 个答案:

没有答案