def non_exiting_main(parser, argv, stdout=None, log_file=None):
    """
    Run the program, and return the exit status without exiting.

    Arguments:
      parser: an argparse.ArgumentParser object.

    """
    args = argv[1:]
    log_level = parser.safe_get_log_level(args)

    if stdout is None:
        stdout = sys.stdout
    with log_config(level=log_level, file_=log_file):
        log.debug("argv: %r" % argv)
        try:
            ns = parser.parse_args(args=args)  # Namespace object
            log.debug(ns % "ns: %r")
            # Make no args default to running help.
            try:
                # There seems to be a bug in argparse where the parent
                # parser's default run_command is used for args like
                # "rcv randcontest" (when nothing is after randcontest),
                # when parser.set_defaults(run_command=...) is used to set
                # the default on the parent parser.  Thus we use try-except
                # here instead.  I believe this is the issue:
                # http://bugs.python.org/issue9351
                command = ns.run_command
            except AttributeError:
                raise HelpRequested(parser=parser)
            output = command(ns, stdout=stdout)
            if output is not None:
                stdout.write(output)
            status = EXIT_STATUS_SUCCESS
        except HelpRequested as exc:
            parser = exc.parser
            parser.print_help(file=stdout)
            status = EXIT_STATUS_SUCCESS
        except UsageException as exc:
            # As of Python 3.4, argparse.ArgumentParser's error() implementation
            # looked like this--
            #   self.print_usage(_sys.stderr)
            #   args = {'prog': self.prog, 'message': message}
            #   self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
            err_args, parser = exc.args, exc.parser
            assert len(err_args) == 1
            print_usage_error(parser, err_args[0], file_=log_file)
            status = EXIT_STATUS_USAGE_ERROR
        # TODO: decide whether to handle the error case manually, or let
        # Python do it by default.  One problem with the former
        # is that exceptions don't show up during test failures.
        # except Exception as err:
            #
            # # Log the full exception info for "unexpected" exceptions.
            # log.error(format_exc())
            # status = EXIT_STATUS_FAIL

    return status


# We follow most of Guido van Rossum's 2003 advice regarding main()
# functions (though we choose _main() as the function that returns an exit
# status rather than main()):
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
dataset/ETHPy150Open cjerdonek/open-rcv/openrcv/scripts/run.py/non_exiting_main/swapped operands of `%`