From 213398528d61df65642e1fd06ea01fddff2dd1c1 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Mon, 12 Feb 2018 16:58:53 +0300 Subject: [PATCH] Stop python process leaked from test before building envs --- python/setup-test-environment/build.gradle | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/python/setup-test-environment/build.gradle b/python/setup-test-environment/build.gradle index d3c7e78007dd..3e5e5da35672 100644 --- a/python/setup-test-environment/build.gradle +++ b/python/setup-test-environment/build.gradle @@ -110,7 +110,15 @@ envs { createPython("django_latest", "3.5.3", ["django"], "python3.5\ndjango", true) } -task prepare (type: Delete) { +/** + * Kills any process named "python" using windows powershell. + * Works on Win7+. + */ +task killPythonWindows(type:Exec) { + commandLine 'powershell', '"Get-Process | where {$_.Name -ieq \\"python\\"} | Stop-Process"' +} + +task prepare(type: Delete) { doFirst { new File(envs.bootstrapDirectory, "django_latest").with { djangoLatestFolder -> if (djangoLatestFolder.exists() && djangoLatestFolder.lastModified() < System.currentTimeMillis() - 24 * 60 * 60 * 1000) { @@ -130,6 +138,13 @@ task prepare (type: Delete) { } } } +prepare.dependsOn { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + // Python leaked from previous test may prevent this script from + // deleting folder because you can't delete file opened by process on Windows + killPythonWindows + } +} task build {