Deadlock fix from @takano-akio and generalized output types

This is code we have been using for a couple of years - I remember discussing these matters with you back then.  At the time I wasn't using github, now that I am I hope we can get all this merged.  It is honest to goodness backwards compatible, and it lets you run processes and read their output lazily.