Skip to content
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

asyncio: replace _compute_returncode() with os.waitstatus_to_exitcode() #84544

Closed
vstinner opened this issue Apr 22, 2020 · 3 comments
Closed
Assignees
Labels
3.10 only security fixes stdlib Python modules in the Lib dir topic-asyncio

Comments

@vstinner
Copy link
Member

BPO 40364
Nosy @vstinner, @asvetlov, @1st1, @corona10, @aeros
PRs
  • bpo-40364: asyncio uses os.waitstatus_to_exitcode() #23798
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/aeros'
    closed_at = <Date 2020-12-16.11:11:45.472>
    created_at = <Date 2020-04-22.16:51:11.732>
    labels = ['library', '3.10', 'expert-asyncio']
    title = 'asyncio: replace _compute_returncode() with os.waitstatus_to_exitcode()'
    updated_at = <Date 2020-12-16.11:11:45.471>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-12-16.11:11:45.471>
    actor = 'vstinner'
    assignee = 'aeros'
    closed = True
    closed_date = <Date 2020-12-16.11:11:45.472>
    closer = 'vstinner'
    components = ['Library (Lib)', 'asyncio']
    creation = <Date 2020-04-22.16:51:11.732>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40364
    keywords = ['patch']
    message_count = 3.0
    messages = ['367021', '367043', '383150']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'asvetlov', 'yselivanov', 'corona10', 'aeros']
    pr_nums = ['23798']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40364'
    versions = ['Python 3.10']

    @vstinner
    Copy link
    Member Author

    I added os.waitstatus_to_exitcode() in bpo-40094. I propose to replace _compute_returncode() with os.waitstatus_to_exitcode() in Lib/asyncio/unix_events.py to simplify the code *and* to raise an exception if asyncio gets an unexpected wait status from os.waitpid().

    There is a comment which suggest to detect when asyncio gets an unexpected status, see the last comment of:

    def _compute_returncode(status):
        if os.WIFSIGNALED(status):
            # The child process died because of a signal.
            return -os.WTERMSIG(status)
        elif os.WIFEXITED(status):
            # The child process exited (e.g sys.exit()).
            return os.WEXITSTATUS(status)
        else:
            # The child exited, but we don't understand its status.
            # This shouldn't happen, but if it does, let's just
            # return that status; perhaps that helps debug it.
            return status

    Replacing _compute_returncode() with os.waitstatus_to_exitcode() in Lib/asyncio/unix_events.py is trivial. The problem is to update Lib/test/test_asyncio/test_unix_events.py which uses tons of mocks on os.W*() functions (ex: os.WIFEXITED()).

    I'm not sure how tests should be updated.

    Is there someone interested to propose a PR for that?

    @vstinner vstinner added 3.9 only security fixes stdlib Python modules in the Lib dir topic-asyncio labels Apr 22, 2020
    @aeros
    Copy link
    Contributor

    aeros commented Apr 22, 2020

    Victor Stinner wrote:

    Is there someone interested to propose a PR for that?

    I would be interested in looking into this, although I'm not entirely certain either as to how it should be tested at the moment. I'll have to look further into the existing ones.

    @vstinner
    Copy link
    Member Author

    New changeset 99d28c5 by Victor Stinner in branch 'master':
    bpo-40364: asyncio uses os.waitstatus_to_exitcode() (GH-23798)
    99d28c5

    @vstinner vstinner added 3.10 only security fixes and removed 3.9 only security fixes labels Dec 16, 2020
    @vstinner vstinner added 3.10 only security fixes and removed 3.9 only security fixes labels Dec 16, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir topic-asyncio
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants