##// END OF EJS Templates
procutil: unroll uin/uout loop in protectstdio()...
Yuya Nishihara -
r37236:ac71cbad default
parent child Browse files
Show More
@@ -221,17 +221,18 b' def protectstdio(uin, uout):'
221 "owned" in that print(), exec(), etc. never reach to them.
221 "owned" in that print(), exec(), etc. never reach to them.
222 """
222 """
223 uout.flush()
223 uout.flush()
224 newfiles = []
225 nullfd = os.open(os.devnull, os.O_RDWR)
224 nullfd = os.open(os.devnull, os.O_RDWR)
226 for f, sysf, mode in [(uin, stdin, r'rb'),
225 fin, fout = uin, uout
227 (uout, stdout, r'wb')]:
226 if uin is stdin:
228 if f is sysf:
227 newfd = os.dup(uin.fileno())
229 newfd = os.dup(f.fileno())
228 os.dup2(nullfd, uin.fileno())
230 os.dup2(nullfd, f.fileno())
229 fin = os.fdopen(newfd, r'rb')
231 f = os.fdopen(newfd, mode)
230 if uout is stdout:
232 newfiles.append(f)
231 newfd = os.dup(uout.fileno())
232 os.dup2(nullfd, uout.fileno())
233 fout = os.fdopen(newfd, r'wb')
233 os.close(nullfd)
234 os.close(nullfd)
234 return tuple(newfiles)
235 return fin, fout
235
236
236 def restorestdio(uin, uout, fin, fout):
237 def restorestdio(uin, uout, fin, fout):
237 """Restore (uin, uout) streams from possibly duplicated (fin, fout)"""
238 """Restore (uin, uout) streams from possibly duplicated (fin, fout)"""
General Comments 0
You need to be logged in to leave comments. Login now