从python代码配置uwsgi

uwsgiconf的Python项目详细描述


https://github.com/idlesign/uwsgiconf

releaseliccicoverage

说明

从python代码中配置uwsgi

如果你认为你知道你可能错了。总是比你想象的要多。 有太多的子系统和options(800+),甚至很难试图把你的思想。

uwsgiconf允许在python中定义uwsgi配置试图通过以下方式改进:

  • 它使用类和方法构造各种子系统的选项;
  • 它使用docstring和合理的命名来方便导航;
  • 它提供了一些有用的预置来减少样板代码;
  • 它鼓励配置重用;
  • 它带有cli以便于配置;
  • 它具有易于使用和文档化的功能uwsgi stubpython模块;
  • 它提供runtime包,类似于uwsgidecorators,但具有更多抽象;
  • 它与django框架集成;
  • 它能够为systemd、upstart生成配置文件。

考虑将ide与自动完成和docsting支持结合使用,以提高uwsgiconf的效率。

这时您已经知道uwsgiconf只是另一种配置方法。Why

概述

静态配置

让我们做uwsgicfg.py。在这里,我们使用nicePythonSection预设配置uwsgi来运行我们的web应用程序。

fromuwsgiconf.configimportconfigure_uwsgifromuwsgiconf.presets.niceimportPythonSectiondefget_configurations():"""This should return one or more Section or Configuration objects.
    In such a way you can configure more than one uWSGI instance in the same place.

    Here we'll define just one configuration section, which
    will instruct uWSGI to serve WSGI application (from wsgi.py module)
    on http://127.0.0.1:8000

    """section=PythonSection(wsgi_module='/home/idle/myapp/wsgi.py',).networking.register_socket(PythonSection.networking.sockets.http('127.0.0.1:8000'))returnsection# Almost done. One more thing:configure_uwsgi(get_configurations)
  1. 现在,如果要生成myconf.ini文件并手动将其用于uwsgi,可以使用:

    $ uwsgiconf compile > myconf.ini
    $ uwsgi myconf.ini
    
  2. 或者使用uwsgiconf为模块中定义的配置自动生成uwsgi进程:

    $ uwsgiconf run
    

注意:uwsgiconfcli需要clickpackage可用(可以与uwsgiconf一起安装)。

运行时配置

uwsgiconf附带了runtimepackage,它类似于uwsgidecorators但提供了不同的抽象。

当实际的抽象不可用时,这些抽象也将使用存根uwsgi模块。

几个例子:

fromuwsgiconf.runtime.lockingimportlockfromuwsgiconf.runtime.schedulingimportregister_timer_rb@register_timer_rb(10,repeat=2)defrepeat_twice():"""This function will be called twice with 10 seconds interval
    (by default in first available mule) using red-black tree based timer.

    """withlock():# Code under this context manager will be locked# using default (0) uWSGI lock.do_something()

第三方

django.使用manage命令在uwsgi上运行基于django的项目:

$ ./manage.py uwsgi_run
$ ./manage.py uwsgi_reload --force

其他命令可用。

系统配置

编译系统服务配置(例如systemd)以运行uwsgi支持的项目:

$ uwsgiconf sysinit systemd

文档

更多信息请访问http://uwsgiconf.readthedocs.org/

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpringbean已创建但未自动连接   java LibGDX游戏在三星Galaxy Grand Prime上结束   如何在Java中列出字符串句子中所有匹配条件的单词   java在Recyclerview中使用“putExtra”传递数据   java从一个特定的数组中提取特定的JSON对象,以便在Android中通过一个意图放入另一个活动   java需要使用IntelliJ和设置项目SDK的帮助   java springcontextindexer和Swagger 3   java使用indexOf和substring计算数字   java使用xml解析在word文档中查找隐式分页符   在添加<context:componentscan basepackage=“com.young.user”/   java无条件更改JTable单元格的背景色   选择列表中的java调用oracle函数:节点无数据类型   java如何添加缓冲图像作为JFrame的背景,然后在此图像上添加面板?   java Javadoc找不到用scala编写的类   java连接到文件共享程序的IP地址   java将数组元素加载到集合中   Tomcat中的java servlet、过滤器和线程   非Bean对象中的java EJB CDI注入?   java与println和printf的不同舍入