def run_once(self): self.loginfo("Starting background docker command, timeout %s seconds", self.config['docker_timeout']) in_pipe_r, in_pipe_w = os.pipe() dkrcmd = AsyncDockerCmd(self, 'run', self.sub_stuff['subargs'], timeout=self.config['docker_timeout']) dkrcmd.verbose = True dkrcmd.timeout = 10 # Runs in background dkrcmd.execute(in_pipe_r) self.sub_stuff['dkrcmd'] = dkrcmd wait = self.config['wait_interactive_cmd'] icmd = self.config['interactive_cmd'] + "\n" # Allow noticable time difference for date command, # and eat into dkrcmd timeout after receiving signal. time.sleep(wait) os.write(in_pipe_w, icmd) self.loginfo("Waiting up to %d seconds for exit", dkrcmd.timeout) # Throw exception if takes > docker_timeout to exit self.loginfo("Container running, waiting %d seconds to finish.", wait) self.logdebug("interactive cmds %s", icmd) time.sleep(wait) os.close(in_pipe_w) dkrcmd.wait()