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

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

Closed
xflr6 mannequin opened this issue Jul 4, 2018 · 5 comments
Closed

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

xflr6 mannequin opened this issue Jul 4, 2018 · 5 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xflr6
Copy link
Mannequin

xflr6 mannequin commented Jul 4, 2018

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']

    @xflr6
    Copy link
    Mannequin Author

    xflr6 mannequin commented Jul 4, 2018

    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

    @xflr6 xflr6 mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 4, 2018
    @vstinner vstinner added the 3.8 only security fixes label Jul 4, 2018
    @vstinner
    Copy link
    Member

    vstinner commented Jul 5, 2018

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

    @vstinner
    Copy link
    Member

    vstinner commented Jul 5, 2018

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

    @vstinner
    Copy link
    Member

    vstinner commented Jul 5, 2018

    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.

    @vstinner vstinner closed this as completed Jul 5, 2018
    @xflr6
    Copy link
    Mannequin Author

    xflr6 mannequin commented Jul 5, 2018

    Perfect, thanks for the quick fix.

    @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.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant