Skip to content

ConPTY doesn't properly terminate Python child processes when mintty terminal is closed #267

Open
@fsagbuya

Description

@fsagbuya

Problem Overview

When using MSYS2 with ConPTY enabled (MSYS=enable_pcon), Python processes that are launched indirectly (as grandchild processes) continue running even after closing the mintty terminal window. However, when using WinPTY as a wrapper (winpty command), these processes terminate correctly.

This particularly affects Python applications that set up network services or long-running processes with this hierarchy:

mintty → executable.exe → python.exe (python_script.py)

Environment

  • MSYS2 runtime version: 3.5.7-4
  • Windows version: 10.0.19045
  • Environment: CLANG64
  • ConPTY: Enabled (MSYS=enable_pcon)
  • Terminal: mintty

Steps to Reproduce

  1. Create a simple Python network service script:
# server.py
import socket
import time
import sys

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 8000))
server.listen(5)
print("Server running on port 8000")

while True:
    time.sleep(1)
  1. Run it via a wrapper script or entry point executable.
  2. Close the mintty terminal window by clicking the X button.
  3. Observe that the Python process continues running in the background (visible in Task Manager or by trying to start another server on the same port).
  4. Try the same with winpty server.exe - this correctly terminates all processes.

Expected Behavior

When closing the mintty terminal window, all child processes (including Python processes) should terminate.

Actual Behavior

The parent process terminates, but the child Python process remains running in the background, keeping network ports open.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions