This is a patch to commands.py to enable callback support, which is very useful for long-running commands. Whenever there is stdout from the process the callback is fed whatever it got. Example usage: import commands cmd = 'top -b -n2' def fancy(out): print 'GOT(%s)' % out.strip() commands.cb = fancy (s,o) = commands.getstatusoutput(cmd) print 'OUTPUT (%s)' % o Please consider adding this. The existing API is not changed, however as you can see it is simple to use the callback.
Your semantic for the cb name seems kind of arbitrary. Why is it called for each line of the output and only once with all the output. Plus, iterating through the output line for line can make it much slower than reading it all at once. Also, the next time you run getstatusoutput(), maybe even from another module, the callback will still be called. That could be unexpected. Plus commands is almost deprecated in favour of subprocess. I recommend rejecting this patch.
Rejecting this for a number of reasons: Module-level globals to be set by the user of a module are bad 1) it is not obvious if it's not set directly before the getstatusoutput() call 2) it's completely confusing with threads 3) commands is quasi-deprecated in favor of subprocess