Skip to content

subprocess: reusing STARTUPINFO breaks under 3.7 (Windows) #78225

Closed

Description

@xflr6
mannequin
BPO 34044
Nosy @vstinner, @eryksun, @xflr6
PRs
  • bpo-34044: subprocess.Popen copies startupinfo #8090
  • [3.7] bpo-34044: subprocess.Popen copies startupinfo (GH-8090) #8120
  • [3.7] bpo-34044: subprocess.Popen copies startupinfo (GH-8090) #8121
  • 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 2018-07-05.21:20:00.049>
    created_at = <Date 2018-07-04.14:55:46.660>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'subprocess: reusing STARTUPINFO breaks under 3.7 (Windows)'
    updated_at = <Date 2018-07-05.22:27:55.180>
    user = 'https://github.com/xflr6'

    bugs.python.org fields:

    activity = <Date 2018-07-05.22:27:55.180>
    actor = 'xflr6'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-07-05.21:20:00.049>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2018-07-04.14:55:46.660>
    creator = 'xflr6'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34044
    keywords = ['patch']
    message_count = 5.0
    messages = ['321047', '321131', '321132', '321133', '321138']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'eryksun', 'xflr6']
    pr_nums = ['8090', '8120', '8121']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34044'
    versions = ['Python 3.7', 'Python 3.8']

    Activity

    1. xflr6 commented on Jul 4, 2018

      xflr6mannequin
      MannequinAuthor

      AFAIU, the change for https://bugs.python.org/issue19764 broke the following usage of subprocess on Windows (re-using a subprocess.STARTUPINFO instance to hide the command window):

          import os, subprocess
      
          STARTUPINFO = subprocess.STARTUPINFO()
          STARTUPINFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
          STARTUPINFO.wShowWindow = subprocess.SW_HIDE
      
          # raises OSError: [WinError 87]
          # in the second loop iteration starting with Python 3.7
          for i in range(2):
              print(i)
              with open(os.devnull, 'w') as stderr:
                  subprocess.check_call(['attrib'], stderr=stderr,
                                        startupinfo=STARTUPINFO)

      AFAICT, this works on Python 2.7, 3.4, 3.5, and 3.6

      I think the documentation in

      https://docs.python.org/3/library/subprocess.html#windows-popen-helpers

      does not mention that every Popen call should be done with a fresh instance, so either the documentation needs to be changed, or the implementation (e.g. by deep-copying the instance).

      See also https://bugs.python.org/issue19764#msg320784

    2. added
      3.7 (EOL)
      stdlib
      type-bug
      on Jul 4, 2018
    3. vstinner commented on Jul 5, 2018

      @vstinner
      Member

      New changeset 483422f by Victor Stinner in branch 'master':
      bpo-34044: subprocess.Popen copies startupinfo (GH-8090)
      483422f

    4. vstinner commented on Jul 5, 2018

      @vstinner
      Member

      New changeset 29be3bd by Victor Stinner in branch '3.7':
      bpo-34044: subprocess.Popen copies startupinfo (GH-8090) (GH-8121)
      29be3bd

    5. vstinner commented on Jul 5, 2018

      @vstinner
      Member

      Sebastian Bank: Thank you for your bug report and your example! I used your example to write an unit test. I fixed the bug in 3.7 and master branches. The fix will be part of the future 3.7.1 release.

    6. xflr6 commented on Jul 5, 2018

      xflr6mannequin
      MannequinAuthor

      Perfect, thanks for the quick fix.

    7. 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.7 (EOL)3.8 (EOL)stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions