zoukankan      html  css  js  c++  java
  • Supervisor:使用

    本文使用supervisor来管理python进程。

    首先创建一个python工程,命名为super27, 新建文件 call.py ,文件内容:

    import datetime
    import os
    import time
    import logging
    
    while True:
        logging.basicConfig(level=logging.NOTSET)
        information = '%s RUN %s' % (os.getpid(), datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        logging.info(information)
        time.sleep(3)

    这个文件内容很简单,每隔三秒输出进程号和当前时间。

    将这个项目放在 /root 目录下,这个文件的全路径是 /root/super27/call.py 。

    编辑supervisor的配置文件,在 /etc 目录下supervisord.conf 添加下面的配置信息

    [program:superman]
    command=python /root/super27/call.py
    numprocs=5
    numprocs_start=5
    process_name=%(program_name)s_%(process_num)s
    
    redirect_stderr=true
    stdout_logfile=/root/super27/result.out

    numprocs是指启动5个进程,并且将日志信息输出到result.out中。

    启动supervisor,可以看到进程已经启动:

    查看result.out文件:

    可以看到日志中每隔三秒就会输出进程号和当前时间。

    自此完成supervisor的使用。

    如何在virtualenv环境中使用supervisor

    pip install virtaulenv

    virtualenv -p /usr/bin/python venv

    source venv/bin/activate

    vim /etc/supervisord.conf

    supervisord -c /etc/supervisord.conf

    自此就完成了在virtualenv环境中启动了supervisor。

  • 相关阅读:
    巡风安装笔记
    泛微ecology OA系统某接口存在数据库配置信息泄露漏洞
    Apache Solr Velocity模板远程代码执行复现
    泛微OA系统多版本存在命令执行漏洞
    各种浏览器UA值
    使用python合并excel
    疑难杂症----udf提权无法导出.dll
    疑难杂症----windows7
    Nmap的使用
    Sqlmap的使用
  • 原文地址:https://www.cnblogs.com/colin220/p/10856242.html
Copyright © 2011-2022 走看看