mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
Patch 1329 (partial) by Christian Heimes.
Add a closefd flag to open() which can be set to False to prevent closing the file descriptor when close() is called or when the object is destroyed. Useful to ensure that sys.std{in,out,err} keep their file descriptors open when Python is uninitialized. (This was always a feature in 2.x, it just wasn't implemented in 3.0 yet.)
This commit is contained in:
parent
2673a57234
commit
2dced8b602
10 changed files with 63 additions and 31 deletions
|
@ -227,12 +227,14 @@ def main():
|
|||
sys.stderr.write("%s: can't open (%s)\n" % (file, msg))
|
||||
sts = 1
|
||||
continue
|
||||
if deco:
|
||||
decode(fp, sys.stdout.buffer)
|
||||
else:
|
||||
encode(fp, sys.stdout.buffer, tabs)
|
||||
if fp is not sys.stdin:
|
||||
fp.close()
|
||||
try:
|
||||
if deco:
|
||||
decode(fp, sys.stdout.buffer)
|
||||
else:
|
||||
encode(fp, sys.stdout.buffer, tabs)
|
||||
finally:
|
||||
if file != '-':
|
||||
fp.close()
|
||||
if sts:
|
||||
sys.exit(sts)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue