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

run_shell_cmd() is stringly typed #341

Open
vext01 opened this issue Sep 18, 2017 · 2 comments
Open

run_shell_cmd() is stringly typed #341

vext01 opened this issue Sep 18, 2017 · 2 comments

Comments

@vext01
Copy link
Member

vext01 commented Sep 18, 2017

I find it annoying that run_shell_cmd wants a string. Because, well, it shouldn't. We pass the argument straight to the Popen constructor.

class subprocess.Popen(args, bufsize=0, executable=None, ...
...
args should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent and described below. See the shell and executable arguments for additional differences from the default behavior. Unless otherwise stated, it is recommended to pass args as a sequence.

Yes, indeed, I'd like to pass them as a sequence too! This saves keystrokes (no join needed) and ensures (god forbid) filenames with spaces work.

So why does run_shell_cmd with ['taskset', '-c', '0', '/home/edd/research/krun/krun/../utils/query_turbo'] give:

Traceback (most recent call last):
  File "../krun.py", line 395, in <module>
    main(parser)
  File "../krun.py", line 240, in main
    raise exn
krun.util.FatalKrunError: Command failed: '['taskset', '-c', '0', '/home/edd/research/krun/krun/../utils/query_turbo']'
stdout:

stderr:
Usage: taskset [options] [mask | cpu-list] [pid|cmd [args...]]


Show or change the CPU affinity of a process.

Options:
 -a, --all-tasks         operate on all the tasks (threads) for a given pid
 -p, --pid               operate on existing given pid
 -c, --cpu-list          display and specify cpus in list format
 -h, --help              display this help
 -V, --version           output version information

The default behavior is to run a new command:
    taskset 03 sshd -b 1024
You can retrieve the mask of an existing task:
    taskset -p 700
Or set it:
    taskset -p 03 700
List format uses a comma-separated list instead of a mask:
    taskset -pc 0,3,7-11 700
Ranges in list format can take a stride argument:
    e.g. 0-31:2 is equivalent to mask 0x55555555

For more details see taskset(1).

You can see it's invoked taskset ok, but something has gone wrong...

If you join the args into a string and use that, this works as expected. Weird.

Pretty sure I'm being daft here...

@ltratt
Copy link
Member

ltratt commented Sep 18, 2017

I wonder if the ../ expansion needs to be done by the shell somewhere?

@vext01
Copy link
Member Author

vext01 commented Sep 18, 2017

Maybe that's it, I think I'll experiment when I get a moment.

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

No branches or pull requests

2 participants