I'm afraid I can't get this right without using ctypes, libc, and ptsname(3). There exists a rare race condition I can't pin down, so I'll just revert it to the way it was. It can only be reproduced by running the tests in a loop, its too time consuming to solve.