anticrash.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:TGCli-Anticrash 作者: Dragon-Born 项目源码 文件源码
def check_bot(self, botname, port, path, user):
        bot = botname

        if not botname in data:

            addlog('starting '+ botname)
            os.chdir(path)
            proc = subprocess.Popen('screen -dmS "'+ botname +'" su '+ user +' -c "bash launch.sh -P '+ str(port) +'"',shell=True).wait()
            addlog(botname + ' has been successfully started')
            print(colored(botname + ' has been successfully started\n',"blue"))
            spid = screen_pid(botname)
            data[botname] = {"pid": spid}
            time.sleep(5)

        while True:
            try:

                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.settimeout(5.0)
                s.connect(('localhost', int(port)))
                s.shutdown(socket.SHUT_WR)
                s.close()
            except:
                try:                
                    os.kill(int(data[botname][pid]), 9)
                except Exception as e:
                 a = 'a'
                wipe = subprocess.Popen(["screen", "-wipe"], stdout=subprocess.PIPE)
                del data[botname]
                addlog(botname + ' was crashed and it has been successfully restarted.')
                print(botname + ' was crashed and it has been successfully restarted.')
                botname = bot+get_random_key(2)

                proc = subprocess.Popen('screen -dmS "'+ botname +'" su '+ user +' -c "bash launch.sh -P '+ str(port) +'"',shell=True).wait()
                spid = screen_pid(botname)
                data[botname] = {"pid": spid}

            time.sleep(15)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号