flush output before showing tracebacks

closes #3700
Merge pull request #4919 from minrk/flush-before-showtraceback

flush output before showing tracebacks