Close kills the child api_server.py process, releasing its resources.
()
| 75 | |
| 76 | // Close kills the child api_server.py process, releasing its resources. |
| 77 | func (i *instance) Close() (err error) { |
| 78 | child := i.child |
| 79 | if child == nil { |
| 80 | return nil |
| 81 | } |
| 82 | defer func() { |
| 83 | i.child = nil |
| 84 | err1 := os.RemoveAll(i.appDir) |
| 85 | if err == nil { |
| 86 | err = err1 |
| 87 | } |
| 88 | }() |
| 89 | |
| 90 | if p := child.Process; p != nil { |
| 91 | errc := make(chan error, 1) |
| 92 | go func() { |
| 93 | errc <- child.Wait() |
| 94 | }() |
| 95 | |
| 96 | // Call the quit handler on the admin server. |
| 97 | res, err := http.Get(i.adminURL + "/quit") |
| 98 | if err != nil { |
| 99 | p.Kill() |
| 100 | return fmt.Errorf("unable to call /quit handler: %v", err) |
| 101 | } |
| 102 | res.Body.Close() |
| 103 | select { |
| 104 | case <-time.After(15 * time.Second): |
| 105 | p.Kill() |
| 106 | return errors.New("timeout killing child process") |
| 107 | case err = <-errc: |
| 108 | // Do nothing. |
| 109 | } |
| 110 | } |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | func fileExists(path string) bool { |
| 115 | _, err := os.Stat(path) |