diff --git a/launch.py b/launch.py index ab42b797514069ce161f660bae7c2e86a0f47623..938abf05c4808358d16d69e5913f3d5105bb2af5 100755 --- a/launch.py +++ b/launch.py @@ -96,7 +96,7 @@ def write_qsub_exe(fname, pbs, tsleep=0.25): return job_id -def write_crontab(): +def write_crontab(every_min=5): """Create a crontab script, and submit to crontab. """ python = '/usr/bin/python' @@ -106,9 +106,9 @@ def write_crontab(): fpath = os.path.join(cwd, 'launch_crontab.sh') # TODO: parse other relevant arguments as well: --re # when using the crontab option, cpu parameters are read from the config - # file if it exists - rpl = (cwd, python, launch) - crontab = '*/5 * * * * cd "%s"; %s %s --crontab ;\n' % rpl + # file if it exists, but only the first run will build a pbslist file + rpl = (every_min, cwd, python, launch) + crontab = '*/%i * * * * cd "%s"; %s %s --crontab --cache ;\n' % rpl f = open(fpath, 'w') f.write(crontab) f.flush() @@ -453,7 +453,7 @@ class Scheduler: else: self.print_config() print ' method ; scheduler' - pbsflist = self.filter_joblist(self.get_joblist()) + pbsflist = self.get_joblist() self.print_logheader() self.launch(pbsflist, crontab_mode=crontab_mode) print '' @@ -469,7 +469,9 @@ class Scheduler: if verbose: print 'Building file list of to be launched jobs. ', print 'Might take a while...' - pbsflist = build_pbsflist(self.path_pbs_files) + # only filter when building the file list. It would be counter + # intuitive to filter a user generated/controlled list. + pbsflist = self.filter_joblist(build_pbsflist(self.path_pbs_files)) if self.sort: pbsflist.sort() save_pbsflist(self.f_pbsflist, pbsflist) @@ -477,8 +479,6 @@ class Scheduler: if verbose: print 'Loading file list from cache...' pbsflist = load_pbsflist(self.f_pbsflist) - if self.sort: - pbsflist.sort() return pbsflist def filter_joblist(self, pbsflist): @@ -533,7 +533,7 @@ class Scheduler: f.write(' tsleep_short : % 5.02f\n' % self.tsleep_short) f.write('pbs_update_deltat : % 5.02f\n' % self.pbs_update_deltat) f.write(' reload_pbsflist : % 5i\n' % self.reload_pbsflist) - f.write(' fname pbsflist : %s\n' % self.f_pbsflist) + f.write(' f_pbsflist : %s\n' % self.f_pbsflist) f.flush() f.close() @@ -880,13 +880,23 @@ if __name__ == '__main__': parser.add_argument('--sort', action='store_true', dest='sort', default=False, help='Sort pbs file list. Default=False') parser.add_argument('--crontab', action='store_true', dest='crontab', - default=False, help='Crontab mode. Implies --cache, ' - 'and not compatible with --node. When all jobs are ' - 'done, crontab -r will remove all the user\'s current ' - 'crontab jobs. Default=False') + default=False, help='Crontab mode: %prog will check ' + 'every 5 (default) minutes if more jobs can be launched. ' + 'Not compatible with --node. When all jobs are done, ' + 'crontab -r will remove all existing crontab jobs of ' + 'the current user. Use crontab -l to inspect current ' + 'crontab jobs, and edit them with crontab -e. ' + 'Default=False') + parser.add_argument('--every_min', action='store', dest='every_min', + type='int', default=5, help='Crontab update interval ' + 'in minutes. Default=5') parser.add_argument('--debug', action='store_true', dest='debug', default=False, help='Debug print statements. Default=False') (options, args) = parser.parse_args() + if options.crontab and options.node: + parser.print_usage() + sys.stderr.write("error: --node and --crontab not compatible" + os.linesep) + sys.exit(1) if options.nr_cpus is None and not options.crontab: parser.print_usage() sys.stderr.write("error: specify number of cpus with -n" + os.linesep) @@ -959,7 +969,7 @@ if __name__ == '__main__': debug=options.debug, cpu_user_queue=options.cpu_user_queue) if options.crontab: if not os.path.exists(os.path.join(os.getcwd(), 'launch_crontab.sh')): - write_crontab() + write_crontab(every_min=options.every_min) if os.path.exists(ss.fname_config): ss.read_config() else: