This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Patch to commands.py to enable callback support
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: bdoctor, georg.brandl, sonderblade
Priority: normal Keywords: patch

Created on 2006-07-05 15:31 by bdoctor, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python_commandsCallBack.diff bdoctor, 2006-07-05 15:31 Patch to commands.py against python 2.4
Messages (3)
msg50610 - (view) Author: Brad Doctor (bdoctor) Date: 2006-07-05 15:31
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.
msg50611 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-07 23:29
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.
msg50612 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-13 20:30
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
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43617
2006-07-05 15:31:24bdoctorcreate