瀏覽代碼

fix intermittent BrokenPipe error on macOS when SHOW_PROGRESS=True

Nick Sweeting 5 年之前
父節點
當前提交
7d4738a674
共有 1 個文件被更改,包括 4 次插入13 次删除
  1. 4 13
      archivebox/logging_util.py

+ 4 - 13
archivebox/logging_util.py

@@ -101,23 +101,14 @@ class TimedProgress:
         if self.SHOW_PROGRESS:
         if self.SHOW_PROGRESS:
             # terminate if we havent already terminated
             # terminate if we havent already terminated
             try:
             try:
-                # WARNING: HACKY
-                # I've spent over 15 hours trying to get rid of this stupid macOS-only  
-                # intermittent (but harmeless) warning when the progress bars end sometimes
-                #     Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
-                #     BrokenPipeError: [Errno 32] Broken pipe
-                # In the end, this is the only thing I found that makes it 
-                # happen slightly less often:
-                if platform.system() == 'Darwin':
-                    time.sleep(0.1)
-
                 # kill the progress bar subprocess
                 # kill the progress bar subprocess
+                try:
+                    self.p.close()   # must be closed *before* its terminnated
+                except:
+                    pass
                 self.p.terminate()
                 self.p.terminate()
                 self.p.join()
                 self.p.join()
-                self.p.close()
 
 
-                if platform.system() == 'Darwin':
-                    time.sleep(0.1)
 
 
                 # clear whole terminal line
                 # clear whole terminal line
                 try:
                 try: