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

[Win] Call subprocess.Popen() twice makes Thread.join() interruptible and deadlock #87575

Closed
zby1234 mannequin opened this issue Mar 5, 2021 · 2 comments
Closed

[Win] Call subprocess.Popen() twice makes Thread.join() interruptible and deadlock #87575

zby1234 mannequin opened this issue Mar 5, 2021 · 2 comments
Labels
3.9 only security fixes OS-windows type-bug An unexpected behavior, bug, or error

Comments

@zby1234
Copy link
Mannequin

zby1234 mannequin commented Mar 5, 2021

BPO 43409
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba
Superseder
  • bpo-21822: [Windows] KeyboardInterrupt during Thread.join hangs that Thread
  • Files
  • joinbug.py
  • 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-03-05.17:51:25.495>
    created_at = <Date 2021-03-05.16:16:07.390>
    labels = ['type-bug', '3.9', 'OS-windows']
    title = '[Win] Call subprocess.Popen() twice makes Thread.join() interruptible and deadlock'
    updated_at = <Date 2021-03-05.17:51:25.494>
    user = 'https://bugs.python.org/zby1234'

    bugs.python.org fields:

    activity = <Date 2021-03-05.17:51:25.494>
    actor = 'eryksun'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-05.17:51:25.495>
    closer = 'eryksun'
    components = ['Windows']
    creation = <Date 2021-03-05.16:16:07.390>
    creator = 'zby1234'
    dependencies = []
    files = ['49853']
    hgrepos = []
    issue_num = 43409
    keywords = []
    message_count = 2.0
    messages = ['388156', '388160']
    nosy_count = 6.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'zby1234']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '21822'
    type = 'behavior'
    url = 'https://bugs.python.org/issue43409'
    versions = ['Python 3.9']

    @zby1234
    Copy link
    Mannequin Author

    zby1234 mannequin commented Mar 5, 2021

    Please run joinbug.py and press Ctrl-C twice.

    ============= The output =============

    1st join
    PLEASE PRESS CTRL-C TWICE, IGNORE THE 'Press any key to continue'
    Press any key to continue . . . Press any key to continue . . .

    thread exit
    Traceback (most recent call last):
      File "D:\xxx\joinbug.py", line 21, in <module>
        t.join() # subprocess.Popen() makes join() can be interrupted
      File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 1033, in join
        self._wait_for_tstate_lock()
      File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 1049, in _wait_for_tstate_lock
        elif lock.acquire(block, timeout):
    KeyboardInterrupt
    2nd join
    (stuck here)

    ============= Expected behaviour =============
    either join uninterruptible
    or the 2nd join doesn't deadlock.

    @zby1234 zby1234 mannequin added 3.9 only security fixes OS-windows type-bug An unexpected behavior, bug, or error labels Mar 5, 2021
    @eryksun
    Copy link
    Contributor

    eryksun commented Mar 5, 2021

    This is a variation on bpo-21822. If join() is called in the main thread, and it gets interrupted immediately after the lock.acquire(block, timeout) call, then subsequent calls will hang. In Windows, the acquire() call is not interruptible with Ctrl+C, so the KeyboardInterrupt gets raised immediately after acquire() returns, so the problem is easy to reproduce in Windows.

    @eryksun eryksun closed this as completed Mar 5, 2021
    @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.9 only security fixes OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant