[Tutor] Consequences of opening subprocesses?

Cory Teshera-Sterne ctsterne at gmail.com
Fri Nov 26 21:16:58 CET 2010

Hi all,

I'm practicing python by rewriting some bash scripts, and I've found a few
things that I can't directly translate, like certain calls to command-line
tools. I've figured out how to start them with the subprocess module, but
I'm wondering if I'm going to get myself in hot water memory- or
performance-wise since these scripts are scheduled to run on thousands of
files fairly often. Do I need to explicitly close the subprocesses, or clean
them up, or something (I have some programming experience, but not a lot of
experience with taking into account these kinds of issues - ie, no C ... )?

An example is a call to the command-line image manipulation program,
s = subprocess.Popen(['identify', '-format', ''%w %h\n'', 'testimg.jpg'],
output = s.communicate()[0]
print output
# output should be the dimensions of testimg.jpg in pixels, ie, 100 50

What I'm thinking is that if, when typed into the terminal, the command
appears to give me some output and then exit like the one above (or bash
commands like "ls -l"), then I'm ok ... but like I said, I just don't know
much about this kind of issue. Can anyone tell me if my intuition's way off
on this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101126/dcc196de/attachment-0001.html>

More information about the Tutor mailing list