schrodinger.job.driver_decorator module

Main function decorator designed for backend jobs. For example:

@driver_decorator.main_wrapper("A super nifty backend")
def main(args):
    do_some_cool_work()
    return 0  # This is optional; None is treated the same as zero.

if __name__ == '__main__':
    args = parse_args()
    main(args)

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.job.driver_decorator.main_wrapper(func, driver_name='Job', *args, **kwargs)

Wrap a main function to print a header before entering the function, a footer after it returns, and exit with the exit status returned by the function (or zero if None). Any return type other than None or int will be interpreted as a fatal error message and result in exit code 1.

If the wrapped function exits by calling sys.exit(), the footer will still be printed the same as if the function had returned whatever was passed to sys.exit().

The wrapper also handles KeyboardInterrupt to produce a less verbose output than the default Python behavior.

When running under job control, a header is printed with the job details. (See jobcontrol.Job.getApplicationHeaderString()).

A footer with the timestamp, elapsed time, and exit status is always printed.

To prevent the footer from being printed after a help message or the like, do the argument parsing before calling the wrapped function.