From e39e14d1572be690a513dff435b639221c35311d Mon Sep 17 00:00:00 2001 From: Helin Wang Date: Wed, 17 May 2017 20:25:47 -0400 Subject: [PATCH] handle error from s.opt.UpdateParameter --- paddle/go/pserver/service.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/paddle/go/pserver/service.go b/paddle/go/pserver/service.go index 22f6cdf40d4..47a862c5ad2 100644 --- a/paddle/go/pserver/service.go +++ b/paddle/go/pserver/service.go @@ -109,6 +109,11 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error { return ErrUnintialized } + count := len(grads) + if count == 0 { + return nil + } + s.mu.Lock() defer s.mu.Unlock() @@ -118,16 +123,25 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error { } } - var wg sync.WaitGroup + errCh := make(chan error, count) for _, g := range grads { - wg.Add(1) go func(p Parameter, g Gradient) { - s.opt.UpdateParameter(p, g) - wg.Done() + err := s.opt.UpdateParameter(p, g) + errCh <- err }(s.paramMap[g.Name], g) } - wg.Wait() + recv := 0 + for err := range errCh { + if err != nil { + return err + } + + recv++ + if recv == count { + break + } + } return nil } -- GitLab