pexpect/pexpect — pull request #146 by takluyver (2014-11-24 02:25:38+00:00)
Title: WIP: Add spawn class based on subprocess.Popen

This will ultimately allow simple uses of Pexpect on Windows. Ping @blink1073 - I copied your gist for the implementation of this.

Open questions:

- At present, `__init__.py` imports `pty_spawn`, so you can't even load Pexpect on Windows. I started doing something along the lines of:

```python
if sys.platform == 'win32':
from .popen_spawn import PopenSpawn as spawn
else:
from .pty_spawn import spawn
```

But that didn't feel quite right; an apparently similar API would be doing something very different internally, which would doubtless lead to surprising bugs. Maybe on Windows the top-level package simply shouldn't have `spawn` and `spawnu`, and we'll leave them in place on Unix for backwards compatibility.

- I'm aiming to make it as close as possible to the applicable parts of the pty_spawn API, but in a couple of places, the Unixy nature of that API conflicts with Popen and cross platform support:
1. `spawn.kill()` takes a signal number. `Popen()` has `.kill()` and `.terminate()`, which send fixed Unix signals (SIGKILL and SIGTERM), and both do TerminateProcess on Windows.
2. `spawn.wait()` returns the raw exit code, a 2-byte number where the high byte is the terminating signal number. `Popen.wait()` uses negative numbers for terminating signals.

My inclination in these cases is that PopenSpawn should stay closer to the cross platform API of Popen, rather than trying to closely copy the pty_spawn interface and being inconsistent between platforms.