sapling/eden/scm/edenscmnative
Jun Wu a90c8ea775 bindings: export rust process handling to Python
Summary:
Spawning processes turns out to be tricky.

Python 2:

- "fork & exec" in plain Python is potentially dangerous. See D22855986 (c35b8088ef).
  Disabling GC might have solved it, but still seems fragile.
- "close_fds=True" works on Windows if there is no redirection.
- Does not work well with `disable_standard_handle_inheritability` from `hgmain`.
  We patched it. See `contrib/python2-winbuild/0002-windows-make-subprocess-work-with-non-inheritable-st.patch`.

Python 3:

- "subprocess" uses native code for "fork & exec". It's safer.
- (>= 3.8) "close_fds=True" works on Windows even with redirection.
- "subprocess" exposes options to tweak low-level details on Windows.

Rust:

- No "close_fds=True" support for both Windows and Unix.
- Does not have the `disable_standard_handle_inheritability` issue on Windows.
- Impossible to cleanly support "close_fds=True" on Windows with existing stdlib.
  https://github.com/rust-lang/rust/pull/75551 attempts to add that to stdlib.
  D23124167 provides a short-term solution that can have corner cases.

Mercurial:

- `win32.spawndetached` uses raw Win32 APIs to spawn processes, bypassing
  the `subprocess` Python stdlib.
- Its use of `CreateProcessA` is undesirable. We probably want `CreateProcessW`
  (unless `CreateProcessA` speaks utf-8 natively).

We are still on Python 2 on Windows, and we'd need to spawn processes correctly
from Rust anyway, and D23124167 kind of fills the missing feature of `close_fds=True`
from Python. So let's expose the Rust APIs.

The binding APIs closely match the Rust API. So when we migrate from Python to
Rust, the translation is more straightforward.

Reviewed By: DurhamG

Differential Revision: D23124168

fbshipit-source-id: 94a404f19326e9b4cca7661da07a4b4c55bcc395
2020-08-31 17:34:48 -07:00
..
bindings bindings: export rust process handling to Python 2020-08-31 17:34:48 -07:00
__init__.py remediation of S205607 2020-07-17 17:16:13 -07:00
clindex.pyi add type annotations for a few more edenscmnative modules 2020-03-20 10:41:32 -07:00
clindex.pyx repoview: further remove repoview references 2020-07-06 14:04:27 -07:00
linelog.pyx py3/cython: set the language_level to 3str 2020-01-30 12:52:06 -08:00
patchrmdir.pyi add type annotations for a few more edenscmnative modules 2020-03-20 10:41:32 -07:00
patchrmdir.pyx py3: fix extdiff 2020-08-27 19:15:22 -07:00
traceprof.pyx py3/cython: set the language_level to 3str 2020-01-30 12:52:06 -08:00