def run(self): try: for line in container_engine.call(f"{self.image}:{self.tag}", self.command, '/data', self.path): print(line) except KeyboardInterrupt: container_engine.shutdown() sys.exit()
def run(self): try: print( container_engine.call( f"staphb/{self.docker_image}:{self.docker_tag}", self.command, '/data', self.path)) except KeyboardInterrupt: container_engine.shutdown() sys.exit()
def run(self): #check if we got a local singularity image if os.path.isfile(self.image): container = self.image else: container = f"{self.image}:{self.tag}" try: for line in container_engine.call(container, self.command, '/data', self.path): print(line) except KeyboardInterrupt: container_engine.shutdown() sys.exit()
def run(self, jobs): #initalize all workers to ignore signal int since we are handeling the keyboard interrupt ourself parent_id = os.getpid() def init_worker(): #set signal for docker since containers are detached and we will kill them separately if which('docker'): signal.signal(signal.SIGINT, signal.SIG_IGN) #for singularity we will kill the child processes when the main process gets a signal else: def sig_int(signal_num, frame): parent = psutil.Process(parent_id) for child in parent.children(): if child.pid != os.getpid(): child.kill() psutil.Process(os.getpid()).kill() signal.signal(signal.SIGINT, sig_int) #create multiprocessing pool pool = mp.Pool(processes=jobs, initializer=init_worker) try: results = pool.starmap_async(container_engine.call, [[ f"staphb/{self.docker_image}:{self.docker_tag}", cmd, '/data', self.path ] for cmd in self.command_list]) stdouts = results.get() except KeyboardInterrupt: pool.terminate() pool.join() #shutdown containers container_engine.shutdown() sys.exit() else: pool.close() pool.join() for stdout in stdouts: print(stdout)