timeout

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2019 License: MIT Imports: 8 Imported by: 45

README

timeout

Build Status Coverage Status MIT License GoDoc

Timeout invocation. Go porting of GNU timeout

Description

Run a given command with a time limit.

Synopsis

tio := &timeout.Timeout{
	Cmd:            exec.Command("perl", "-E", "say 'Hello'"),
	Duration:       10 * time.Second,
	KillAfter:      5 * time.Second,
}
exitStatus, stdout, stderr, err := tio.Run()

Author

Songmu

Documentation

Overview

Package timeout is for handling timeout invocation of external command

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	ExitCode int
	Err      error
}

Error is error of timeout

func (*Error) Error

func (err *Error) Error() string

type ExitStatus

type ExitStatus struct {
	Code     int
	Signaled bool
	// contains filtered or unexported fields
}

ExitStatus stores exit information of the command

func (*ExitStatus) GetChildExitCode

func (ex *ExitStatus) GetChildExitCode() int

GetChildExitCode gets the exit code of the Cmd itself

func (*ExitStatus) GetExitCode

func (ex *ExitStatus) GetExitCode() int

GetExitCode gets the exit code for command line tools

func (*ExitStatus) IsCanceled added in v0.3.0

func (ex *ExitStatus) IsCanceled() bool

IsCanceled return if the command canceled by context or not

func (*ExitStatus) IsKilled

func (ex *ExitStatus) IsKilled() bool

IsKilled returns the command is killed or not

func (*ExitStatus) IsTimedOut

func (ex *ExitStatus) IsTimedOut() bool

IsTimedOut returns the command timed out or not

type Timeout

type Timeout struct {
	Duration   time.Duration
	KillAfter  time.Duration
	Signal     os.Signal
	Foreground bool
	Cmd        *exec.Cmd

	KillAfterCancel time.Duration
}

Timeout is main struct of timeout package

func (*Timeout) Run

func (tio *Timeout) Run() (*ExitStatus, string, string, error)

Run is synchronous interface of executing command and returning information

func (*Timeout) RunCommand

func (tio *Timeout) RunCommand() (<-chan *ExitStatus, error)

RunCommand is executing the command and handling timeout. This is primitive interface of Timeout

func (*Timeout) RunContext added in v0.3.0

func (tio *Timeout) RunContext(ctx context.Context) (*ExitStatus, error)

RunContext runs command with context

func (*Timeout) RunSimple

func (tio *Timeout) RunSimple(preserveStatus bool) int

RunSimple executes command and only returns integer as exit code. It is mainly for go-timeout command

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL