##// END OF EJS Templates
subprocessio: don't use __del__ to close the buffers and readers. Instead use a finally block....
dan -
r799:825a2f59 default
parent child Browse files
Show More
@@ -1137,11 +1137,12 b' class GitRemote(RemoteBase):'
1137 1137 cmd = [settings.GIT_EXECUTABLE] + _copts + cmd
1138 1138 _opts = {'env': gitenv, 'shell': False}
1139 1139
1140 proc = None
1140 1141 try:
1141 1142 _opts.update(opts)
1142 p = subprocessio.SubprocessIOChunker(cmd, **_opts)
1143 proc = subprocessio.SubprocessIOChunker(cmd, **_opts)
1143 1144
1144 return ''.join(p), ''.join(p.error)
1145 return ''.join(proc), ''.join(proc.error)
1145 1146 except (EnvironmentError, OSError) as err:
1146 1147 cmd = ' '.join(cmd) # human friendly CMD
1147 1148 tb_err = ("Couldn't run git command (%s).\n"
@@ -1153,6 +1154,9 b' class GitRemote(RemoteBase):'
1153 1154 return '', err
1154 1155 else:
1155 1156 raise exceptions.VcsException()(tb_err)
1157 finally:
1158 if proc:
1159 proc.close()
1156 1160
1157 1161 @reraise_safe_exceptions
1158 1162 def install_hooks(self, wire, force=False):
@@ -216,9 +216,6 b' class BufferedGenerator(object):'
216 216 except (GeneratorExit, StopIteration):
217 217 pass
218 218
219 def __del__(self):
220 self.close()
221
222 219 ####################
223 220 # Threaded reader's infrastructure.
224 221 ####################
@@ -475,26 +472,23 b' class SubprocessIOChunker(object):'
475 472 self._closed = True
476 473 try:
477 474 self.process.terminate()
478 except:
475 except Exception:
479 476 pass
480 477 if self._close_input_fd:
481 478 os.close(self._close_input_fd)
482 479 try:
483 480 self.output.close()
484 except:
481 except Exception:
485 482 pass
486 483 try:
487 484 self.error.close()
488 except:
485 except Exception:
489 486 pass
490 487 try:
491 488 os.close(self.inputstream)
492 except:
489 except Exception:
493 490 pass
494 491
495 def __del__(self):
496 self.close()
497
498 492
499 493 def run_command(arguments, env=None):
500 494 """
@@ -506,18 +500,20 b' def run_command(arguments, env=None):'
506 500
507 501 cmd = arguments
508 502 log.debug('Running subprocessio command %s', cmd)
503 proc = None
509 504 try:
510 505 _opts = {'shell': False, 'fail_on_stderr': False}
511 506 if env:
512 507 _opts.update({'env': env})
513 p = SubprocessIOChunker(cmd, **_opts)
514 stdout = ''.join(p)
515 stderr = ''.join(''.join(p.error))
508 proc = SubprocessIOChunker(cmd, **_opts)
509 return ''.join(proc), ''.join(proc.error)
516 510 except (EnvironmentError, OSError) as err:
517 511 cmd = ' '.join(cmd) # human friendly CMD
518 512 tb_err = ("Couldn't run subprocessio command (%s).\n"
519 513 "Original error was:%s\n" % (cmd, err))
520 514 log.exception(tb_err)
521 515 raise Exception(tb_err)
516 finally:
517 if proc:
518 proc.close()
522 519
523 return stdout, stderr
General Comments 0
You need to be logged in to leave comments. Login now