File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 66# - preserve signal handling of subprocess (kill -TERM and friends)
77# - tee output to a log file
88
9+ import errno
910import fcntl
1011import os
1112import select
@@ -44,7 +45,7 @@ def main():
4445 break
4546 # raise Exception if log_file could not be set
4647 if log_file is None:
47- raise Exception("Could not open '.jupyter-server-log.txt' log file " )
48+ raise Exception("Could not open '.jupyter-server-log.txt' log file" )
4849
4950 # build the command
5051 # like `exec "$@"`
@@ -73,12 +74,27 @@ def main():
7374 for signum in SIGNALS:
7475 signal.signal(signum, relay_signal)
7576
77+ # keep a record of the output streams that ran out space
78+ writable = {
79+ sys.stdout.buffer: True,
80+ log_file: True
81+ }
82+
7683 # tee output from child to both our stdout and the log file
7784 def tee(chunk):
7885 """Tee output from child to both our stdout and the log file"""
7986 for f in [sys.stdout.buffer, log_file]:
80- f.write(chunk)
81- f.flush()
87+ if writable[f]:
88+ try:
89+ f.write(chunk)
90+ f.flush()
91+ except OSError as e:
92+ if e.errno == errno.ENOSPC:
93+ # mark the stream as not writable anymore
94+ writable[f] = False
95+ continue
96+ else:
97+ raise
8298
8399 # make stdout pipe non-blocking
84100 # this means child.stdout.read(nbytes)
@@ -106,6 +122,8 @@ def main():
106122 tee(chunk)
107123 chunk = child.stdout.read()
108124
125+ log_file.close()
126+
109127 # make our returncode match the child's returncode
110128 sys.exit(child.returncode)
111129
You can’t perform that action at this time.
0 commit comments