未验证 提交 75f00b96 编写于 作者: A Alessandro Arzilli 提交者: GitHub

terminal: add way to cancel goroutines command with ctrl-C (#2278)

The goroutines command can take a long time to complete if there are
many goroutines, add the possibility to terminate it early by pressing
ctrl-C.
上级 6726ec3a
......@@ -723,7 +723,12 @@ func goroutines(t *Term, ctx callContext, argstr string) error {
gslen = 0
gs []*api.Goroutine
)
t.longCommandStart()
for start >= 0 {
if t.longCommandCanceled() {
fmt.Printf("interrupted\n")
return nil
}
gs, start, err = t.client.ListGoroutines(start, goroutineBatchSize)
if err != nil {
return err
......
......@@ -66,6 +66,9 @@ type Term struct {
// should be resumed before quitting.
quitContinue bool
longCommandMu sync.Mutex
longCommandCancelFlag bool
quittingMutex sync.Mutex
quitting bool
}
......@@ -123,6 +126,7 @@ func (t *Term) Close() {
func (t *Term) sigintGuard(ch <-chan os.Signal, multiClient bool) {
for range ch {
t.longCommandCancel()
t.starlarkEnv.Cancel()
state, err := t.client.GetStateNonBlocking()
if err == nil && state.Recording {
......@@ -481,6 +485,24 @@ func (t *Term) onStop() {
t.printDisplays()
}
func (t *Term) longCommandCancel() {
t.longCommandMu.Lock()
defer t.longCommandMu.Unlock()
t.longCommandCancelFlag = true
}
func (t *Term) longCommandStart() {
t.longCommandMu.Lock()
defer t.longCommandMu.Unlock()
t.longCommandCancelFlag = false
}
func (t *Term) longCommandCanceled() bool {
t.longCommandMu.Lock()
defer t.longCommandMu.Unlock()
return t.longCommandCancelFlag
}
// isErrProcessExited returns true if `err` is an RPC error equivalent of proc.ErrProcessExited
func isErrProcessExited(err error) bool {
rpcError, ok := err.(rpc.ServerError)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册