Don't do I/O if the thread is interrupted.

(cherry picked from commit 664b65d18e164a571a2c8498fe372d3f934499c3)