kopia lustrzana https://github.com/jupyterhub/repo2docker
Merge pull request #1151 from pymonger/handle-logfile-permission-error
handle permission issue writing .jupyter-server-log.txt in REPO_DIRpull/1156/head
commit
61247bec16
|
@ -12,6 +12,7 @@ import select
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
# output chunk size to read
|
# output chunk size to read
|
||||||
CHUNK_SIZE = 1024
|
CHUNK_SIZE = 1024
|
||||||
|
@ -23,11 +24,23 @@ SIGNALS = set(signal.Signals) - {signal.SIGKILL, signal.SIGSTOP, signal.SIGCHLD}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
# open log file to send output
|
# open log file to send output to;
|
||||||
log_file = open(
|
# preferred location of log file is:
|
||||||
os.path.join(os.environ.get("REPO_DIR", "."), ".jupyter-server-log.txt"),
|
# 1. REPO_DIR env variable
|
||||||
"ab",
|
# 2. current working directory: "."
|
||||||
)
|
# 3. default temp directory for the OS (e.g. /tmp for linux)
|
||||||
|
log_dirs = [".", tempfile.gettempdir()]
|
||||||
|
if "REPO_DIR" in os.environ:
|
||||||
|
log_dirs.insert(0, os.environ["REPO_DIR"])
|
||||||
|
for d in log_dirs:
|
||||||
|
log_path = os.path.join(d, ".jupyter-server-log.txt")
|
||||||
|
try:
|
||||||
|
log_file = open(log_path, "ab")
|
||||||
|
except PermissionError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# success
|
||||||
|
break
|
||||||
|
|
||||||
# build the command
|
# build the command
|
||||||
# like `exec "$@"`
|
# like `exec "$@"`
|
||||||
|
|
Ładowanie…
Reference in New Issue