msys2-runtime icon indicating copy to clipboard operation
msys2-runtime copied to clipboard

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

Open fsagbuya opened this issue 9 months ago β€’ 2 comments

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.

fsagbuya avatar Mar 19 '25 09:03 fsagbuya

keeping network ports open.

You can see the issue without involving sockets, just looking at the process manager, can't you?

sbourdeauducq avatar Mar 24 '25 04:03 sbourdeauducq

You can see the issue without involving sockets, just looking at the process manager, can't you?

Yes, the issue isn’t specific to sockets. A simple script running in a continuous loop can also exhibit the same behavior.

fsagbuya avatar Mar 24 '25 05:03 fsagbuya