Skip to content

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

Closed

Description

@zby1234
mannequin
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']

    Activity

    1. zby1234 commented on Mar 5, 2021

      zby1234mannequin
      MannequinAuthor

      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.

    2. eryksun commented on Mar 5, 2021

      @eryksun
      Contributor

      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.

    3. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions