Skip to content

Commit

Permalink
:p: Enable process check for linux only
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnjack committed Dec 18, 2023
1 parent 3749142 commit 25dfdfc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -105,18 +106,20 @@ func acquireLock(envDir string, attempt int) error {
}

// Lockfile is not stale, check if there is a process which uses the venv
_, err := findProcessWithPrefix(envDir)
if err == ErrNoProcessFound {
if flagDebug {
loggerErr.Printf("process which is using virtual environment not found, removing lockfile %s\n", lockFileName)
}
err = os.Remove(lockFileName)
if err != nil {
return err
if runtime.GOOS == "linux" {
_, err := findProcessWithPrefix(envDir)
if err == ErrNoProcessFound {
if flagDebug {
loggerErr.Printf("process which is using virtual environment not found, removing lockfile %s\n", lockFileName)
}
err = os.Remove(lockFileName)
if err != nil {
return err
}
}
}

// Lockfile is not stale, wait for 1 second and try again
// Virtual environment is still in use, wait for a second and try again
time.Sleep(1 * time.Second)
return acquireLock(envDir, attempt+1)
}
Expand Down

0 comments on commit 25dfdfc

Please sign in to comment.