def kill(self): import os import signal job = self.getJobObject() ok = True try: # kill the wrapper script # bugfix: #18178 - since wrapper script sets a new session and new # group, we can use this to kill all processes in the group os.kill(-self.wrapper_pid, signal.SIGKILL) except OSError as x: logger.warning('while killing wrapper script for job %s: pid=%d, %s', job.getFQID('.'), self.wrapper_pid, str(x)) ok = False # waitpid to avoid zombies try: ws = os.waitpid(self.wrapper_pid, 0) except OSError as x: logger.warning('problem while waitpid %s: %s', job.getFQID('.'), x) from Ganga.Utility.files import recursive_copy for fn in ['stdout', 'stderr', '__syslog__']: try: recursive_copy( os.path.join(self.workdir, fn), job.getOutputWorkspace().getPath()) except Exception as x: logger.info('problem retrieving %s: %s', fn, x) self.remove_workdir() return 1
def createOutputSandbox(output_patterns, filter, dest_dir): """Get all files matching output patterns except filtered with filter and write them to the destination directory. This function is called by wrapper script at the run time. Arguments: 'output_patterns': list of filenames or patterns. 'filter': function to filter files (return True to except) 'dest_dir': destination directory for output files """ try: from Ganga.Utility.files import multi_glob, recursive_copy except IOError as e: import sys print("Failed to import files") print("sys:") print(sys.path) print("env:") print(os.environ) print("ls:") print(os.listdir(".")) print("pattern:") print(output_patterns) print("destdir:") print(dest_dir) try: import traceback traceback.print_stack() except: pass print("Trying fix") sys.path.insert(0, os.path.join(os.getcwd(), PYTHON_DIR)) try: from Ganga.Utility.files import multi_glob, recursive_copy print("Success!") except IOError as e: print("Fail!") raise e for f in multi_glob(output_patterns, filter): try: if not os.path.exists(dest_dir): os.makedirs(dest_dir) recursive_copy(f, dest_dir) except Exception as x: print("ERROR: (job ###JOBID### createOutput )", x)
def createOutputSandbox(output_patterns,filter,dest_dir): """Get all files matching output patterns except filtered with filter and write them to the destination directory. This function is called by wrapper script at the run time. Arguments: 'output_patterns': list of filenames or patterns. 'filter': function to filter files (return True to except) 'dest_dir': destination directory for output files """ from Ganga.Utility.files import multi_glob,recursive_copy for f in multi_glob(output_patterns,filter): try: recursive_copy(f,dest_dir) except Exception,x: print "ERROR: (job ###JOBID### createOutput )",x
os.kill(-self.wrapper_pid,signal.SIGKILL) except OSError,x: logger.warning('while killing wrapper script for job %d: pid=%d, %s',job.id,self.wrapper_pid,str(x)) ok = False # waitpid to avoid zombies try: ws = os.waitpid(self.wrapper_pid,0) except OSError,x: logger.warning('problem while waitpid %d: %s',job.id,x) from Ganga.Utility.files import recursive_copy for fn in ['stdout','stderr','__syslog__']: try: recursive_copy(os.path.join(self.workdir,fn),job.getOutputWorkspace().getPath()) except Exception,x: logger.info('problem retrieving %s: %s',fn,x) self.remove_workdir() return 1 def remove_workdir(self): if config['remove_workdir']: import shutil try: shutil.rmtree(self.workdir) except OSError,x: logger.warning('problem removing the workdir %s: %s',str(self.id),str(x)) def updateMonitoringInformation(jobs):