从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第三方库


热门话题
java JBPM:无法部署进程存档:null   java将一个数组拆分为两个大小相等的数组   java Spring boot验证该字段是否为string类型   JAVA JPA保存到TSV而不是SQL   java PMD报告超过X个违规   java是否支持springdatagremlin中的自定义查询?   java在“for”循环后使用变量   JPQL中默认查询中的java错误列   如何在java中实现不同于线程的进程?   java如何检查字符串是否平衡?   xml使用xalan扩展在XSL中处理java集合   java我试图使用子类/超类重写另一个类的值   转换为JSON时出现java堆栈溢出问题   java考虑定义一个类型为“COM”的bean。实例演示。在您的配置中命令$DefaultIO   java在kubernetes中如何检索转发端口的值?   JavaEclipse,动态web项目,向类路径添加另一个eclipse项目   eclipse的java Spring上下文XML验证器?   Linux下利用MATLAB(Windows)生成Java包   Java:在存储到DDC之前验证属性   java校验字符串