diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-05-16 17:15:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 17:15:47 +0200 |
commit | 5f74fe9cf281128171d1ee7dc03e3a14972f1825 (patch) | |
tree | 07e8f5a191308ce0859dd559f76be5efd0418c19 /testing | |
parent | b702d7d32a9edec41cd2dad81dcf39107c1c5ddc (diff) | |
parent | 18dec100cc21de643470cfd9554f36daf9cb8273 (diff) | |
download | UXP-5f74fe9cf281128171d1ee7dc03e3a14972f1825.tar UXP-5f74fe9cf281128171d1ee7dc03e3a14972f1825.tar.gz UXP-5f74fe9cf281128171d1ee7dc03e3a14972f1825.tar.lz UXP-5f74fe9cf281128171d1ee7dc03e3a14972f1825.tar.xz UXP-5f74fe9cf281128171d1ee7dc03e3a14972f1825.zip |
Merge pull request #366 from alaviss/bug1384062
Make SystemResourceMonitor.stop more resilient to errors
Diffstat (limited to 'testing')
-rw-r--r-- | testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py b/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py index 8e908bf43..56a1f0ef7 100644 --- a/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py +++ b/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py @@ -289,26 +289,45 @@ class SystemResourceMonitor(object): assert self._running assert not self._stopped - self._pipe.send(('terminate',)) + try: + self._pipe.send(('terminate',)) + except Exception: + pass self._running = False self._stopped = True self.measurements = [] - done = False - # The child process will send each data sample over the pipe # as a separate data structure. When it has finished sending # samples, it sends a special "done" message to indicate it # is finished. - while self._pipe.poll(1.0): - start_time, end_time, io_diff, cpu_diff, cpu_percent, virt_mem, \ - swap_mem = self._pipe.recv() + + # multiprocessing.Pipe is not actually a pipe on at least Linux. that + # has an effect on the expected outcome of reading from it when the + # other end of the pipe dies, leading to possibly hanging on revc() + # below. So we must poll(). + def poll(): + try: + return self._pipe.poll(0.1) + except Exception: + # Poll might throw an exception even though there's still + # data to read. That happens when the underlying system call + # returns both POLLERR and POLLIN, but python doesn't tell us + # about it. So assume there is something to read, and we'll + # get an exception when trying to read the data. + return True + while poll(): + try: + start_time, end_time, io_diff, cpu_diff, cpu_percent, virt_mem, \ + swap_mem = self._pipe.recv() + except Exception: + # Let's assume we're done here + break # There should be nothing after the "done" message so # terminate. if start_time == 'done': - done = True break io = self._io_type(*io_diff) @@ -325,11 +344,6 @@ class SystemResourceMonitor(object): if self._process.is_alive(): self._process.terminate() self._process.join(10) - else: - # We should have received a "done" message from the - # child indicating it shut down properly. This only - # happens if the child shuts down cleanly. - assert done if len(self.measurements): self.start_time = self.measurements[0].start |