<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, 9 Jan 2018 at 02:42 Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 9 January 2018 at 20:01, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>> wrote:<br>
> On Mon, 08 Jan 2018 09:11:38 +0000<br>
> Pablo Galindo Salgado <<a href="mailto:pablogsal@gmail.com" target="_blank">pablogsal@gmail.com</a>> wrote:<br>
>> Hi,<br>
>><br>
>> I'm currently working on exposing posix_spawn in the posix module (and by<br>
>> extension in the os module). You can find the initial implementation in<br>
>> this PR:<br>
>><br>
>> <a href="https://github.com/python/cpython/pull/5109" rel="noreferrer" target="_blank">https://github.com/python/cpython/pull/5109</a><br>
>><br>
>> As pointed out by Gregory P. Smith, some changes are needed in the way the<br>
>> file_actions arguments is passed from Python. For context, posix_spawn has<br>
>> the following declaration:<br>
>><br>
>> int posix_spawn(pid_t *pid, const char *path,<br>
>> const posix_spawn_file_actions_t *file_actions,<br>
>> const posix_spawnattr_t *attrp,<br>
>> char *const argv[], char *const envp[]);<br>
>><br>
>> Here, file_actions is an object that represents a list of file actions<br>
>> (open, close or dup2) that is populated using helper functions on the C API.<br>
>><br>
>> The question is: what is the best way to deal with this argument?<br>
><br>
> How about a list of tuples like:<br>
> [(os.SPAWN_OPEN, 4, 'README.txt', os.O_RDONLY, 0),<br>
> (os.SPAWN_CLOSE, 5),<br>
> (os.SPAWN_DUP2, 3, 6),<br>
> ]<br>
><br>
> I don't expect this API to be invoked directly by user code so it<br>
> doesn't have to be extremely pretty.<br>
<br>
I'll note that one advantage of this approach is that it ties in well<br>
with how the C API is going to have to deal with it anyway: a switch<br>
statement dispatching on the first value, and then passing the<br>
remaining arguments to the corresponding posix_file_actions API.<br></blockquote><div><br></div><div>Plus the posix module tends to stick reasonably close to the C API anyway since it's such a thin wrapper.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Wrapping it all up in a more Pythonic self-validating API would then<br>
be the responsibility of the subprocess module (in the standard<br>
library), or third party modules.<br></blockquote><div><br></div><div>+1 from me on Antoine's suggestion. Might as well keep it simple.<br></div><div> </div></div></div>