@@ -45,7 +45,7 @@ class PythonEnvManager(private val workDir: String) {
4545 Log .info(" Mamba already installed at: " + dstFile.path)
4646 }
4747
48- fun createEnv (name : String , version : String = "3.11.4"): PythonEnv {
48+ fun createEnv (name : String , version : String = "3.11.4", retries : Int = 5 ): PythonEnv {
4949 Log .info(" Python environment is creating." )
5050 val errPrefix = " Error occurred during Python environment creation:"
5151 val pyenv = PythonEnv (Paths .get(mambaWorkDir, " envs" , name).toString())
@@ -64,23 +64,34 @@ class PythonEnvManager(private val workDir: String) {
6464 " --yes"
6565 )
6666 Log .info(" Preparing to create python environment by: $command " )
67- try {
68- ProcessBuilder (* command).start().also { process ->
69- process.inputStream.bufferedReader().forEachLine { Log .info(" [Mamba installation] $it " ) }
70- val exitCode = process.waitFor()
71- if (exitCode != 0 ) throw RuntimeException (
72- " Command execution failed with exit code: $exitCode "
67+
68+ var remainingRetries: Int = retries
69+ while (remainingRetries-- > 0 ) {
70+ try {
71+ ProcessBuilder (* command).start().also { process ->
72+ process.inputStream.bufferedReader().forEachLine { Log .info(" [Mamba installation] $it " ) }
73+ val exitCode = process.waitFor()
74+ if (exitCode == 0 ) {
75+ Log .info(" Python is installed in: $pythonBinPath " )
76+ return pyenv
77+ }
78+ Log .warn(
79+ " $errPrefix Command execution failed with exit code $exitCode , $remainingRetries retries left"
80+ )
81+ }
82+ } catch (e: IOException ) {
83+ e.printStackTrace()
84+ Log .warn(
85+ " $errPrefix Exception occurred while executing the command: ${e.message} , $remainingRetries retries left"
86+ )
87+ } catch (e: InterruptedException ) {
88+ Thread .currentThread().interrupt()
89+ Log .warn(
90+ " $errPrefix Command execution was interrupted: ${e.message} , $remainingRetries retries left"
7391 )
7492 }
75- } catch (e: IOException ) {
76- throw RuntimeException (" $errPrefix Command execution failed with exception: " + e.message, e)
77- } catch (e: InterruptedException ) {
78- Thread .currentThread().interrupt()
79- throw RuntimeException (" $errPrefix Command execution was interrupted: " + e.message, e)
8093 }
81-
82- Log .info(" Python is installed in: $pythonBinPath " )
83- return pyenv
94+ throw RuntimeException (" $errPrefix Maximum retries exceed" )
8495 }
8596}
8697
0 commit comments