os.execv Overhead

M

mark.mcdowall

I have a script that automates running a program X times by preparing
the required files and passing the external program right variables.

What I am unsure about though is the overhead of:

program = "externalScript"
variables = ["-i", "var1"]
pid = os.fork()
if not pid:
os.execv(program, [program] + variables)
os.wait()

Whether there would be a more efficient way of making such a call.

Any comments would be greatfully appreciated.
 
J

Jim Wilson

overhead of [fork/exec]:

An alternative might be os.spawn?(), etal. It might run a tiny bit faster
because it combines the two operations, but I think you're pretty close to the
metal.

Jim
 
N

Nobody

I have a script that automates running a program X times by preparing
the required files and passing the external program right variables.

What I am unsure about though is the overhead of:

program = "externalScript"
variables = ["-i", "var1"]
pid = os.fork()
if not pid:
os.execv(program, [program] + variables)
os.wait()

Whether there would be a more efficient way of making such a call.

I would expect the overhead to be dominated by the underlying fork() and
execve() system calls, rather than anything within Python.

OTOH, using subprocess.call() wouldn't be any slower, and is more portable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top