From 9af103c673818ea0f44000e3bc49fa2b14237ac6 Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 7 Mar 2016 15:12:30 +0100 Subject: [PATCH] fixes for handling failed chdir in spawners --- jupyterhub/spawner.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jupyterhub/spawner.py b/jupyterhub/spawner.py index 019f1d55..9691fd2e 100644 --- a/jupyterhub/spawner.py +++ b/jupyterhub/spawner.py @@ -11,7 +11,7 @@ import signal import sys import grp from subprocess import Popen -from tempfile import TemporaryDirectory +from tempfile import mkdtemp from tornado import gen from tornado.ioloop import IOLoop, PeriodicCallback @@ -328,12 +328,13 @@ def _try_setcwd(path): try: os.chdir(path) except OSError as e: + exc = e # break exception instance out of except scope print("Couldn't set CWD to %s (%s)" % (path, e), file=sys.stderr) path, _ = os.path.split(path) else: return - print("Couldn't set CWD at all (%s), using temp dir" % e, file=sys.stderr) - td = TemporaryDirectory().name + print("Couldn't set CWD at all (%s), using temp dir" % exc, file=sys.stderr) + td = mkdtemp() os.chdir(td)