Skip to content

Commit

Permalink
Change how to set maxprocs with a revert function.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Oct 24, 2024
1 parent d16c73c commit a8ccec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/automaxprocs/maxprocs"
)

const (
Expand All @@ -30,6 +31,13 @@ func run() error {
// Create a logger
logger := log.New(os.Stdout, "", log.LstdFlags)

// Configure max processes
undoFn, err := maxprocs.Set()
if err != nil {
logger.Printf("Unable to set max procs: %s -- will continue without setting them", err)
undoFn()
}

// Create a piped reader/writer for logging
// then intercept logging statements as they
// come to prepend dates
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"fmt"
"os"

_ "go.uber.org/automaxprocs"
)

func main() {
Expand Down

0 comments on commit a8ccec5

Please sign in to comment.