Niether of these worked for Python. However, the first one did cause "Cleanup successful\n" to be printed to the screen when calling client in gambit/tests.
Try commenting out the body of ___device_tty_cleanup in lib/os_tty.c so that you only keep:
return ___FIX(___NO_ERR);
Then try to only keep
#ifdef USE_POSIX if (close (d->fd) < 0) return err_code_from_errno (); #endif
return ___FIX(___NO_ERR);