-
Notifications
You must be signed in to change notification settings - Fork 18
Add verbosity to smart-dispatch #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| #!/usr/bin/env python2 | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import argparse | ||
| import logging | ||
| import os | ||
| import sys | ||
| import argparse | ||
| import time as t | ||
| from os.path import join as pjoin | ||
| from textwrap import dedent | ||
|
|
@@ -16,9 +17,12 @@ from smartdispatch import get_available_queues | |
| from smartdispatch import launch_jobs | ||
| from smartdispatch import utils | ||
|
|
||
| import logging | ||
| import smartdispatch | ||
|
|
||
|
|
||
| logger = logging.getLogger() | ||
|
|
||
|
|
||
| LOGS_FOLDERNAME = "SMART_DISPATCH_LOGS" | ||
| CLUSTER_NAME = utils.detect_cluster() | ||
| AVAILABLE_QUEUES = get_available_queues(CLUSTER_NAME) | ||
|
|
@@ -29,27 +33,50 @@ TIMEOUT_EXIT_CODE = 124 | |
| AUTORESUME_TRIGGER_AFTER = '$(($PBS_WALLTIME - 60))' # By default, 60s before the maximum walltime. | ||
| AUTORESUME_WORKER_CALL_PREFIX = 'timeout -s TERM {trigger_after} '.format(trigger_after=AUTORESUME_TRIGGER_AFTER) | ||
| AUTORESUME_WORKER_CALL_SUFFIX = ' WORKER_PIDS+=" $!"' | ||
| AUTORESUME_PROLOG = 'WORKER_PIDS=""' | ||
| AUTORESUME_PROLOG = """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the
|
||
| WORKER_PIDS="" | ||
| VERBOSE={verbose} | ||
| """ | ||
| AUTORESUME_EPILOG = """\ | ||
| NEED_TO_RESUME=false | ||
| if [ $VERBOSE = true ]; then | ||
| echo NEED_TO_RESUME=$NEED_TO_RESUME | ||
| echo WORKER_PIDS=$WORKER_PIDS | ||
| fi | ||
| for WORKER_PID in $WORKER_PIDS; do | ||
| if [ $VERBOSE = true ]; then | ||
| echo WORKER_PID=$WORKER_PID | ||
| fi | ||
| wait "$WORKER_PID" | ||
| RETURN_CODE=$? | ||
| if [ $VERBOSE = true ]; then | ||
| echo "RETURN_CODE is $RETURN_CODE while " \ | ||
| "timeout_exit_code is {timeout_exit_code}" | ||
| fi | ||
| if [ $RETURN_CODE -eq {timeout_exit_code} ]; then | ||
| NEED_TO_RESUME=true | ||
| fi | ||
| if [ $VERBOSE = true ]; then | ||
| echo NEED_TO_RESUME=$NEED_TO_RESUME | ||
| fi | ||
| done | ||
| if [ $VERBOSE = true ]; then | ||
| echo NEED_TO_RESUME=$NEED_TO_RESUME | ||
| fi | ||
| if [ "$NEED_TO_RESUME" = true ]; then | ||
| echo "Autoresuming using: {{launcher}} $PBS_FILENAME" | ||
| sd-launch-pbs --launcher {{launcher}} $PBS_FILENAME {{path_job}} | ||
| if [ $VERBOSE = true]; then | ||
| VERBOSE_OPTION="-vv" | ||
| else | ||
| VERBOSE_OPTION="" | ||
| fi | ||
|
|
||
| sd-launch-pbs $VERBOSE_OPTION --launcher {{launcher}} $PBS_FILENAME {{path_job}} | ||
| fi | ||
| """.format(timeout_exit_code=TIMEOUT_EXIT_CODE) | ||
|
|
||
|
|
||
| def main(): | ||
| # Necessary if we want 'logging.info' to appear in stderr. | ||
| logging.root.setLevel(logging.INFO) | ||
|
|
||
| args = parse_arguments() | ||
| path_smartdispatch_logs = pjoin(os.getcwd(), LOGS_FOLDERNAME) | ||
|
|
||
|
|
@@ -163,8 +190,12 @@ def main(): | |
| prolog = [] | ||
| epilog = ['wait'] | ||
| if args.autoresume: | ||
| prolog = [AUTORESUME_PROLOG] | ||
| epilog = [AUTORESUME_EPILOG.format(launcher=LAUNCHER if args.launcher is None else args.launcher, path_job=path_job)] | ||
| prolog = [ | ||
| AUTORESUME_PROLOG.format(verbose=str(args.verbose >= 2).lower())] | ||
| epilog = [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This project follows the entirety of PEP8 but the 80 columns. |
||
| AUTORESUME_EPILOG.format( | ||
| launcher=LAUNCHER if args.launcher is None else args.launcher, | ||
| path_job=path_job)] | ||
|
|
||
| job_generator = job_generator_factory(queue, commands, prolog, epilog, command_params, CLUSTER_NAME, path_job) | ||
|
|
||
|
|
@@ -187,6 +218,13 @@ def main(): | |
|
|
||
| def parse_arguments(): | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| parser.add_argument( | ||
| '-v', '--verbose', action='count', default=0, | ||
| help="Print informations about the process.\n" | ||
| " -v: INFO\n" | ||
| " -vv: DEBUG") | ||
|
|
||
| parser.add_argument('-q', '--queueName', required=True, help='Queue used (ex: qwork@mp2, qfat256@mp2, gpu_1)') | ||
| parser.add_argument('-n', '--batchName', required=False, help='The name of the batch. Default: The commands launched.') | ||
| parser.add_argument('-t', '--walltime', required=False, help='Set the estimated running time of your jobs using the DD:HH:MM:SS format. Note that they will be killed when this time limit is reached.') | ||
|
|
@@ -226,6 +264,13 @@ def parse_arguments(): | |
| if args.coresPerCommand < 1: | ||
| parser.error("coresPerNode must be at least 1") | ||
|
|
||
| if args.verbose == 0: | ||
| logging.basicConfig(level=logging.WARNING) | ||
| elif args.verbose == 1: | ||
| logging.basicConfig(level=logging.INFO) | ||
| elif args.verbose >= 2: | ||
| logging.basicConfig(level=logging.DEBUG) | ||
|
|
||
| return args | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the logging.root.setLevel(logging.INFO) below and make sure the default throughout the system is warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgermain Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even in the rest of the smartdispatch to stay consistent?