Fixed support for ipython notebook: shell execution was falling over
because sys.stdout is some internal object (not supporting .fileno())
under the notebook. The workaround should support this case.