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。

  • 相关阅读:
    mfc给对话框添加背景
    科学计数法中的尾数、基、指数
    格式化输出符号详细说明(待补充)
    写入注册表
    C++ 注册表操作
    Run-Time Check Failure #3
    完美二叉树, 完全二叉树和完满二叉树学习
    GetModuleFileNameW
    [BJDCTF2020]ZJCTF,不过如此
    picoctf_2018_buffer overflow 1/2
  • 原文地址:https://www.cnblogs.com/colin220/p/10856242.html
Copyright © 2011-2022 走看看