Skip to content

Gradle doesn't stop forked processes #7603

@tx46

Description

@tx46

When a program is started by Gradle and is long-running, and the user presses ctrl-c during that time, Gradle is killed but the subprocess started by Gradle keeps running.

NOTE 1: This seems to affect Windows only!
NOTE 2: This also only seems to affect bat scripts started by Gradle, not executables. So Gradle -> bat -> exe leaves the exe running on ctrl-c.

Expected Behavior

Both Gradle and Python exits.

Current Behavior

Gradle exits, but Python keeps running:

image

Context

It causes the following: Access denied problems (because files are kept locked), memory leak issues, build errors

Steps to Reproduce (for bugs)

File: freeze.py

import time
i = 0
while 1:
  print(i)
  i += 1
  time.sleep(1)

File: build.gradle

task dummy {
  doLast {
    exec {
      commandLine 'python.bat', 'freeze.py'
    }
  }
}

File: python.bat

@python.exe $*
  1. Put the files build.gradle, python.bat and freeze.py into the same directory, with contents copied from above.
  2. Start cmd.exe
  3. Chdir into the directory
  4. Enter gradle dummy
  5. Press ctrl+c

Your Environment

  • Build scan URL:
------------------------------------------------------------
Gradle 4.10
------------------------------------------------------------

Build time:   2018-08-27 18:35:06 UTC
Revision:     ee3751ed9f2034effc1f0072c2b2ee74b5dce67d

Kotlin DSL:   1.0-rc-3
Kotlin:       1.2.60
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          10.0.2 ("Oracle Corporation" 10.0.2+13)
OS:           Windows 10 10.0 amd64

NOTE: Gradle 5/nightly is also affected

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions