Skip to content
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

integration: add background runner script #1594

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbungert
Copy link
Collaborator

To eventually run these in parallel, we want to not have a single test instance hogging the console. Add a background-runner script which uses a detached screen session that also preserves the exit code of the program we're testing.

To eventually run these in parallel, we want to not have a single test
instance hogging the console.  Add a background-runner script which uses
a detached screen session that also preserves the exit code of the
program we're testing.
Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to work and seems like progress!

@@ -0,0 +1,35 @@
#!/usr/bin/python3

# Use screen to run a terminal program in the background until it exists.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exists/exits/

#!/usr/bin/python3

# Use screen to run a terminal program in the background until it exists.
# This process stays around in the forground.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/forground/foreground/

'-D', '-m', # run detached from a terminal perspective,
# but the screen process doesn't background
]
if args.logfile:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not None?

parser = argparse.ArgumentParser()
parser.add_argument('-l', '--logfile', default=None,
help='append output to logfile')
args, program = parser.parse_known_args()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadly, there seems to be no way to tell argparse to parse options only at the beginning of the CLI. This means that doing:

scripts/background-runner ls -l /root

will interpret /root as the logfile for background-runner, and not an option of ls.

I suggest to disable prefix matching (i.e., setting allow_abbrev=False when instantiating ArgumentParser) to at least avoid stealing options that look like valid background-runner options.

Another alternative is to insert -- between the background-runner options and the rest of the CLI, e.g.:

scripts/background-runner -- ls -l

but with parse_known_args, argparse considers -- to be an extra argument, so it ends up first in program. We would need to remove it manually before calling subprocess.run:

parser.parse_known_args(["-l", "/tmp/log", "--", "ls", "/root"])
(Namespace(logfile='/tmp/log'), ['--', 'ls', '/root'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants