Question

In case both options available: to call a command line tool with subprocess (say, hg) or to make use of native python API (say, mercurial API), is there a case where it's more favorable to use the former?

Was it helpful?

Solution

If you want to execute some third party native code which you know is not stable and may crash with a segvault then it is better to execute it as a subprocess - you will be able to safely handle the possible crashes from your Python process.

Also, if you want to call several times some code which is known to leak memory, leave open files or other resources, from a long running Python process, then again it may be wise to run it as a subprocess. In this case the leaking memory or other resources will be reclaimed by the operating system for you each time the subprocess exits, and not accumulate.

OTHER TIPS

The only way that i see myself using subprocess instead of a native python api is if some option of the program is not provided in the api.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top