I'm capturing the stderr of my script to I can later save to a database via:
ostderr = sys.stderr
sys.stderr = StringIO()
# do stuff
mymodel.errors = sys.stderr.getvalue()
mymodel.save()
print mymodel.errors
sys.stderr = ostderr
Unfortunately, this makes casual debugging more difficult because if any errors occur, I won't see them until the script terminates.
How do I capture stderr in a string, as I'm doing above, but still display it in realtime to the console?