os.execv Overhead

Nobody nobody at nowhere.com
Thu Sep 17 06:08:26 EDT 2009


On Wed, 16 Sep 2009 08:12:50 -0700, mark.mcdowall at gmail.com wrote:

> 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.




More information about the Python-list mailing list