Fix usage of Popen().poll() and settimeout_raw

Make exit detection and error codes work properly.

Also fixes #40.