'Check that a partial write, when it gets interrupted, properly
invokes the signal handler, and bubbles up the exception raised
in the latter.'

@unittest.skipUnless(threading, 'Threading    required    for    this    test.')
def check_interrupted_write(self, item, bytes, **fdopen_kwargs):

    read_results = []
    def _read():
        if hasattr(signal, 'pthread_sigmask'):
            signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGALRM])
        s = os.read(r, 1)
        read_results.append(s)
    t = threading.Thread(target=_read)
    t.daemon = True
    (r, w) = os.pipe()
    fdopen_kwargs['closefd'] = False
    try:
        wio = self.io.open(w, **fdopen_kwargs)
        t.start()
        signal.alarm(1)
        try:
            self.assertRaises(ZeroDivisionError, wio.write, (item * ((support.PIPE_MAX_SIZE // len(item)) + 1)))
        finally:
            signal.alarm(0)
        t.join()
        read_results.append(os.read(r, 1))
        self.assertEqual(read_results, [bytes[0:1], bytes[1:2]])
    finally:
        os.close(w)
        os.close(r)
        try:
            wio.close()
        except OSError as e:
            if (e.errno != errno.EBADF):
                raise
