python多线程
python多线程
eddy_linux 发表于2年前
python多线程
  • 发表于 2年前
  • 阅读 12
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

#!/usr/bin/env python
# encoding: utf-8
#  17.51/52:
#
import os
import threading
import sys
def execCmd(cmd):
    try:
        os.system(cmd)
    except Exception, e:
        print '%s\t 运行失败,失败原因\r\n%s' % (cmd,e)

if __name__ == '__main__':
    start_cmds = [
#            ' su - tomcat -c "/data/program/payment/payment-ac/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-account/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-agent/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-ams/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-business/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel-ota/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel-realnameAuth/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-cm/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-cms/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-fastdfs/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-mas/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-order/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-pe/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-pss/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-rcs/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-route/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-security/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-settle/bin/start.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-tasks/bin/start.sh" ',
        ]
    stop_cmds = [
#            ' su - tomcat -c "/data/program/payment/payment-ac/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-account/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-agent/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-ams/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-business/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel-ota/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-channel-realnameAuth/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-cm/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-cms/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-fastdfs/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-mas/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-order/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-pe/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-pss/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-rcs/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-route/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-security/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-settle/bin/stop.sh" ',
#            ' su - tomcat -c "/data/program/payment/payment-tasks/bin/stop.sh" ',
        ]
        status_cmds = [
    #            ' ps -ef | grep "/data/program/payment/payment-ac" ',
    #            ' ps -ef | grep "/data/program/payment/payment-account" ',
    #            ' ps -ef | grep "/data/program/payment/payment-agent" ',
    #            ' ps -ef | grep "/data/program/payment/payment-ams" ',
    #            ' ps -ef | grep "/data/program/payment/payment-business" ',
    #            ' ps -ef | grep "/data/program/payment/payment-channel" ',
    #            ' ps -ef | grep "/data/program/payment/payment-channel-ota" ',
    #            ' ps -ef | grep "/data/program/payment/payment-channel-realnameAuth" ',
    #            ' ps -ef | grep "/data/program/payment/payment-cm" ',
    #            ' ps -ef | grep "/data/program/payment/payment-cms" ',
    #            ' ps -ef | grep "/data/program/payment/payment-fastdfs" ',
    #            ' ps -ef | grep "/data/program/payment/payment-mas/bin" ',
    #            ' ps -ef | grep "/data/program/payment/payment-order" ',
    #            ' ps -ef | grep "/data/program/payment/payment-pe/bin" ',
    #            ' ps -ef | grep "/data/program/payment/payment-pss" ',
    #            ' ps -ef | grep "/data/program/payment/payment-rcs" ',
    #            ' ps -ef | grep "/data/program/payment/payment-route" ',
    #            ' ps -ef | grep "/data/program/payment/payment-security" ',
    #            ' ps -ef | grep "/data/program/payment/payment-settle" ',
    #            ' ps -ef | grep "/data/program/payment/payment-tasks" ',
            ]
    if sys.argv[1] == 'start':
        threads = []
        for cmd in start_cmds:
            th = threading.Thread(target=execCmd, args=(cmd,))
            th.start()
            threads.append(th)
            for th in threads:
                th.join()
    elif sys.argv[1] == 'stop':
        threads = []
        for cmd in stop_cmds:
            th = threading.Thread(target=execCmd, args=(cmd,))
            th.start()
            threads.append(th)
            for th in threads:
                th.join()
    elif sys.argv[1] == 'status':
        threads = []
        for cmd in status_cmds:
            th = threading.Thread(target=execCmd, args=(cmd,))
            th.start()
            threads.append(th)
            for th in threads:
                th.join()
    elif sys.argv == '-h':
        print 'python 17_improper_update.py start|stop|status'
    else:
        print 'python 17_improper_update.py start|stop|status'


共有 人打赏支持
粉丝 19
博文 132
码字总数 185568
×
eddy_linux
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: