comparison mercurial/commandserver.py @ 37124:6715e8035b4f

procutil: introduce context-manager interface for protect/restorestdio The code looks slightly cleaner since it was pretty easy to pass arguments in wrong order.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Mar 2018 11:58:05 +0900
parents 0216232f21ab
children 6f9ac3cb0987
comparison
equal deleted inserted replaced
37123:0216232f21ab 37124:6715e8035b4f
316 316
317 def run(self): 317 def run(self):
318 ui = self.ui 318 ui = self.ui
319 # redirect stdio to null device so that broken extensions or in-process 319 # redirect stdio to null device so that broken extensions or in-process
320 # hooks will never cause corruption of channel protocol. 320 # hooks will never cause corruption of channel protocol.
321 fin, fout = procutil.protectstdio(ui.fin, ui.fout) 321 with procutil.protectedstdio(ui.fin, ui.fout) as (fin, fout):
322 try: 322 try:
323 sv = server(ui, self.repo, fin, fout) 323 sv = server(ui, self.repo, fin, fout)
324 return sv.serve() 324 return sv.serve()
325 finally: 325 finally:
326 sv.cleanup() 326 sv.cleanup()
327 procutil.restorestdio(ui.fin, ui.fout, fin, fout)
328 327
329 def _initworkerprocess(): 328 def _initworkerprocess():
330 # use a different process group from the master process, in order to: 329 # use a different process group from the master process, in order to:
331 # 1. make the current process group no longer "orphaned" (because the 330 # 1. make the current process group no longer "orphaned" (because the
332 # parent of this process is in a different process group while 331 # parent of this process is in a different process group while