在服务器上运行一个无限循环的命令,然后在1分钟后使用ssh-python终止

在服务器上运行一个无限循环的命令,然后在1分钟后使用ssh-python终止,python,python-3.x,Python,Python 3.x,我编写了创建ssh连接的代码。连接成功,我正在执行gstreamer的命令,该命令无休止地运行。我需要在5分钟后杀死它并执行另一个管道 def execute_pipeline(self,): print("-------------") stdin, stdout, stderr = self.ssh_client.exec_command( command='ls -ll') for cfg in config.se

我编写了创建ssh连接的代码。连接成功,我正在执行
gstreamer
的命令,该命令无休止地运行。我需要在5分钟后杀死它并执行另一个管道

  def execute_pipeline(self,):
        print("-------------")
        stdin, stdout, stderr = self.ssh_client.exec_command(
            command='ls -ll')
        for cfg in config.serial_pipeline:
            stdin, stdout, stderr = self.ssh_client.exec_command(
                command='/media/gst %s' % cfg)
            self.ssh_client.exec_command(command="killall -9 gst")
            print(stderr.readlines())
            self.execute_disply_pipe()

            logcreator.log_writer(stdout, cfg)

如果第一个命令被执行,那么它将无法执行下一行如何以异步方式处理这些事情?

在后台运行
gstreamer
命令
/media/gst%s&
然后执行put sleep命令

 def execute_pipeline(self,):
        print("-------------")
        stdin, stdout, stderr = self.ssh_client.exec_command(
            command='ls -ll')
        for cfg in config.serial_pipeline:
            stdin, stdout, stderr = self.ssh_client.exec_command(
                command='/media/gst %s &' % cfg)
            self.ssh_client.exec_command(command="sleep 60")
            self.ssh_client.exec_command(command="killall -9 gst")
            print(stderr.readlines())
            self.execute_disply_pipe()

            logcreator.log_writer(stdout, cfg)
使用kill gst进程使用此命令

"ps | grep gst | awk '{print $1}' | xargs kill -2 $1"

在后台运行第一个命令。在放入
sleep 60
之后,如果我在后台运行,则运行kill命令,使用&cany我可以在stdout中获取日志。readlines()。因为我想看日志。我将假设管道运行正常,或者出现了错误,比如validationi使用了timeout 1m/media/gst