Skip to content

cross plateform library to have only one instance of a software (based on python's tendo)

License

Notifications You must be signed in to change notification settings

allan-simon/go-singleinstance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-singleinstance

Cross plateform library to have only one instance of a software (based on python's tendo).

Usage

package main

import (
	"fmt"
	"time"

	"github.com/allan-simon/go-singleinstance"
)

func main() {
	lockFile, err := singleinstance.CreateLockFile("plop.lock")
	if err != nil {
		fmt.Println("An instance already exists")
		return
	}
	defer lockFile.Close()

	fmt.Println("Sleeping...")
	time.Sleep(10 * time.Second)
	fmt.Println("Done")
}

If you try to launch it twice, the second instance will fail.

Thanks

For the python library trendo, from which I've shamelessly adapted the code.

Contribution

Don't be afraid if it says "last commit 2 years ago", this library is made to be small and simple so it's unlikely it changes after some times, however I'm pretty reactive on github overall, so feel free to use issues to ask question, propose patch etc. :)

License

MIT

About

cross plateform library to have only one instance of a software (based on python's tendo)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages