统一 handle/fd RAII
你现在代码里:
Windows HANDLE
Unix fd
pipe fd
process handle
thread handle
生命周期还比较分散。
第一步:建立统一 native_handle wrapper
例如:
class unique_fd;
class unique_handle;
要求:
move only
自动 close
release/reset
bool 有效性
native_handle()
然后:pipe,process, thread, stdin/stdout/stderr
全部使用它。
因为 subprocess 最大问题永远是:
early return
exception
partial init failure
timeout cleanup
只要 RAII 没统一:后面所有优化都危险
统一 handle/fd RAII
你现在代码里:
Windows HANDLE
Unix fd
pipe fd
process handle
thread handle
生命周期还比较分散。
第一步:建立统一 native_handle wrapper
例如:
class unique_fd;
class unique_handle;
要求:
move only
自动 close
release/reset
bool 有效性
native_handle()
然后:pipe,process, thread, stdin/stdout/stderr
全部使用它。
因为 subprocess 最大问题永远是:
early return
exception
partial init failure
timeout cleanup
只要 RAII 没统一:后面所有优化都危险