Skip to content

bpo-20104: Add flag capabilities to posix_spawn #6693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 7, 2018

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented May 2, 2018

@pablogsal pablogsal force-pushed the complete_posix_spawn branch 3 times, most recently from b838fd6 to eec6215 Compare May 2, 2018 11:07
@pablogsal
Copy link
Member Author

@vstinner @serhiy-storchaka Please, review and once we are happy with the interface and implementation we can add new tests for the flags in this PR.

@pablogsal pablogsal changed the title bpo-20104: Add flag capabilities to posix_spawn bpo-20104: Add flag capabilities to posix_spawn DO NOT MERGE May 2, 2018
@pablogsal
Copy link
Member Author

pablogsal commented May 2, 2018

This implementation is missing setting the POSIX_SPAWN_SETSCHEDPARAM flag implementation because I am not sure what is the best way to actually implement the interface to set the scheduler parameters unsing posix_spawnattr_setschedparam. Any ideas?

@pablogsal pablogsal force-pushed the complete_posix_spawn branch 11 times, most recently from 6946cd3 to 55d1b3d Compare May 2, 2018 18:04
@gpshead gpshead requested a review from serhiy-storchaka May 2, 2018 21:49
@pablogsal
Copy link
Member Author

@gpshead @serhiy-storchaka I have implemented the existing flags as keyword-only arguments as suggested in the issue. The question of what to do with POSIX_SPAWN_SETSCHEDPARAM remains.

@pablogsal pablogsal force-pushed the complete_posix_spawn branch 2 times, most recently from 395e7af to 457ea58 Compare May 5, 2018 19:22
@@ -5292,9 +5418,15 @@ os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
file_actionsp = &file_actions_buf;
}

if (parse_posix_spawn_flags(setpgroup, resetids, setsigmask,
Copy link
Member Author

@pablogsal pablogsal May 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that in case that non of the flags are set the attr object is still created (with no flags or arguments set). This is to avoid wrapping these lines in

    if ((setpgroup != Py_None) | (resetids != Py_True) | (setsigmask != Py_None)
        | (setsigdef != Py_None) | (setscheduller != Py_None) ) {
                   ...
     }

As far as I understand there is no different between this and passing NULL to posix_spawn.

@pablogsal pablogsal force-pushed the complete_posix_spawn branch 4 times, most recently from 31bb4bc to 98e005a Compare May 6, 2018 00:18
@@ -5114,6 +5114,165 @@ enum posix_spawn_file_actions_identifier {
POSIX_SPAWN_DUP2
};

static int
iterable_to_sigset(PyObject *iterable, sigset_t *mask)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that this same function exists in Modules/signalmodule.c but is private (static). I did not want to export that symbol in libpython so I recreated the function here. Please, advise if you think a header/extern declaration should be created and the function should be exported (in this case we will need to name it properly).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. A future refactoring can combine these if ever desired (and if both extension modules are statically linked, a good linker would merge them as being identical anyways).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though I see Serhiy diagreeing, follow his lead.

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Jul 24, 2018
with self.assertRaises(TypeError):
posix.posix_spawn(sys.executable,
[sys.executable, "-c", "pass"],
os.environ, resetids=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for rejecting 0 as false? resetids=0 seems legit to me.

Why not using "bool" type for this parameter? Something like:

@@ -5416,7 +5411,7 @@ os.posix_spawn
     *
     setpgroup: object = NULL
         The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
-    resetids: object = False
+    resetids: bool = False
         If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
     setsigmask: object(c_default='NULL') = ()
         The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use bool then the truthiness value of the object will be used. This will allow the user to pass anything there (ant the boolean value of the argument will be used), right?

I would prefer to pass only True or False (maybe 0 and 1 as well) but not any object.

with self.assertRaises(ValueError):
posix.posix_spawn(sys.executable,
[sys.executable, "-c", "pass"],
os.environ, setsigmask=[9998, 9999])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a more explicit signal.NSIG rather than arbitrary integer 9999. Maybe [signal.NSIG, signal.NSIG+1]?


pid2, status = os.waitpid(pid, 0)
self.assertEqual(pid2, pid)
self.assertNotEqual(status, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a stricter test:

    self.assertTrue(os.WIFSIGNALED(status), status)
    self.assertEqual(os.WTERMSIG(status), signal.SIGUSR1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vstinner
Copy link
Member

The overall change LGTM, but I have a few questions/suggestions.

@@ -3392,7 +3392,9 @@ written in Python, such as a mail server's external command delivery program.
subprocesses.


.. function:: posix_spawn(path, argv, env, file_actions=None)
.. function:: posix_spawn(path, argv, env, file_actions=None, /, *, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this / should be here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #6725.

@pablogsal
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@vstinner, @serhiy-storchaka: please review the changes made to this pull request.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@pablogsal pablogsal merged commit 254a466 into python:master Sep 7, 2018
@pablogsal pablogsal deleted the complete_posix_spawn branch September 7, 2018 15:44
@vstinner
Copy link
Member

vstinner commented Sep 7, 2018

Yeah! It's now time to see how to use it in subprocess :-)

@serhiy-storchaka
Copy link
Member

I don't see a use case for it in the stdlib.

@vstinner
Copy link
Member

vstinner commented Sep 9, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants