##// 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 221 "owned" in that print(), exec(), etc. never reach to them.
222 222 """
223 223 uout.flush()
224 newfiles = []
225 224 nullfd = os.open(os.devnull, os.O_RDWR)
226 for f, sysf, mode in [(uin, stdin, r'rb'),
227 (uout, stdout, r'wb')]:
228 if f is sysf:
229 newfd = os.dup(f.fileno())
230 os.dup2(nullfd, f.fileno())
231 f = os.fdopen(newfd, mode)
232 newfiles.append(f)
225 fin, fout = uin, uout
226 if uin is stdin:
227 newfd = os.dup(uin.fileno())
228 os.dup2(nullfd, uin.fileno())
229 fin = os.fdopen(newfd, r'rb')
230 if uout is stdout:
231 newfd = os.dup(uout.fileno())
232 os.dup2(nullfd, uout.fileno())
233 fout = os.fdopen(newfd, r'wb')
233 234 os.close(nullfd)
234 return tuple(newfiles)
235 return fin, fout
235 236
236 237 def restorestdio(uin, uout, fin, fout):
237 238 """Restore (uin, uout) streams from possibly duplicated (fin, fout)"""
General Comments 0
You need to be logged in to leave comments. Login now