已安装 uWSGI,但未在 Python 中导入

uWSGI installed, but not being imported in Python

在 Ubuntu 16.04.5 上使用 Python 3.5.2,安装了 uwsgi 2.0.17.1(最新稳定版)。我目前正在尝试使用模块 flask-uwsgi-websocket 编写简单的 websocket 乒乓服务器。为了优雅退出(这是进一步开发所必需的,因为这个项目不会最终相互乒乓),我用谷歌搜索发现我必须导入 uwsgi 模块并挂钩我的 func。 Python 内置的信号方法或 onexit 方法对我不起作用。

这就是问题所在。我可以通过 uwsgi 运行 我的程序,使用任何选项,也可以使用 .ini 文件,但不能在 Python 中导入 uwsgi 模块。 python 包列表中有 uWSGI 模块(显示在 PyCharm 中)。我已经尝试通过构建它并使用 pip 重新安装它,但结果是一样的。

我应该怎么做才能在我的脚本中导入 uwsgi 模块?

文档中描述了您的案例Python Module

The uWSGI server automagically adds a uwsgi module into your Python apps.

This is useful for configuring the uWSGI server, use its internal functions and get statistics. Also useful for detecting whether you’re actually running under uWSGI; if you attempt to import uwsgi and receive an ImportError you’re not running under uWSGI.

这意味着只有当您通过 uwsgi 运行 时才能导入 uwsgi。