Skip to content

Use WinAPI GetFileType() in is_valid_fd() #90077

Closed

Description

@eryksun
BPO 45919
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @corona10
PRs
  • bpo-45919: Use WinAPI GetFileType() in is_valid_fd() #30082
  • bpo-45919: Remove out of date comment #30090
  • 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 = None
    closed_at = <Date 2021-12-13.13:06:50.961>
    created_at = <Date 2021-11-28.19:21:47.738>
    labels = ['interpreter-core', 'easy', 'type-feature', 'OS-windows', '3.11']
    title = 'Use WinAPI GetFileType() in is_valid_fd()'
    updated_at = <Date 2021-12-14.01:31:45.274>
    user = 'https://github.com/eryksun'

    bugs.python.org fields:

    activity = <Date 2021-12-14.01:31:45.274>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-12-13.13:06:50.961>
    closer = 'corona10'
    components = ['Interpreter Core', 'Windows']
    creation = <Date 2021-11-28.19:21:47.738>
    creator = 'eryksun'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45919
    keywords = ['patch', 'easy (C)']
    message_count = 3.0
    messages = ['407221', '408449', '408511']
    nosy_count = 6.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'corona10']
    pr_nums = ['30082', '30090']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue45919'
    versions = ['Python 3.11']

    Activity

    1. eryksun commented on Nov 28, 2021

      @eryksun
      ContributorAuthor

      During startup, is_valid_fd() in Python/pylifecycle.c is called to validate stdin, stdout, and stderr. Performance isn't critical here, but every bit helps in reducing startup time. In my tests, implementing this check in Windows via GetFileType((HANDLE)_get_osfhandle(fd)) is 5-6 times faster than close(dup(fd)). For example:

      #if defined(MS_WINDOWS)
          HANDLE hfile;
          _Py_BEGIN_SUPPRESS_IPH
          hfile = (HANDLE)_get_osfhandle(fd);
          _Py_END_SUPPRESS_IPH
          return (hfile != INVALID_HANDLE_VALUE &&
                    GetFileType(hfile) != FILE_TYPE_UNKNOWN);
      #endif
    2. corona10 commented on Dec 13, 2021

      @corona10
      Member

      New changeset 191c431 by Dong-hee Na in branch 'main':
      bpo-45919: Use WinAPI GetFileType() in is_valid_fd() (GH-30082)
      191c431

    3. corona10 commented on Dec 14, 2021

      @corona10
      Member

      New changeset 9130a4d by Dong-hee Na in branch 'main':
      bpo-45919: Remove out of date comment (GH-30090)
      9130a4d

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesOS-windowseasyinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions