Skip to content

Commit

Permalink
be more careful about opening files
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Feb 1, 2024
1 parent 65548e3 commit fc5b577
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
#

_last_type = None
_open_files = { 0: sys.stdin, 1: sys.stdout, 2: sys.stderr}
def print_msg(mtype, *msgs):
global _last_type #pylint:disable=global-statement
#pylint:disable=global-statement
global _last_type

fd = getattr(_args, f"chio_{mtype}_fd")
fd = getattr(_args, f"chio_{mtype}_fd") #pyltint:disable=used-before-assignment
if fd == -1:
return
f = sys.stdin if fd == 0 else sys.stdout if fd == 1 else sys.stderr if fd == 2 else os.fdopen(fd, "w")
if fd not in _open_files:
_open_files[fd] = os.fdopen(fd, "w")
f = _open_files[fd]
if _last_type and _last_type != mtype:
print("", file=f)
_last_type = mtype
Expand Down

0 comments on commit fc5b577

Please sign in to comment.