msys2 / msys2/msys2-runtime

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

Open
#267 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
240
Forks
60
Avg merge
2d 3h
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the process hierarchy with the provided server.py example under mintty with ConPTY enabled, then compare it with the winpty behavior. Trace the MSYS2 runtime's child-process termination path; done means closing minty terminates the Python child and releases its network port.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.