Merge pull request
#1907 from minrk/py3script
py3compat fixes for %%script and tests.
fixes hang in test_pr, caused by error raised in background thread (%%script --bg), and main thread waiting on the close of an FD that would never close due to the error.