Skip to content

Commit d92e430

Browse files
author
Armin Burgmeier
committed
Avoid creating default connection dir if not needed
If a connection file is specified with an absolute path via the '-f' command line option, ipykernel still makes sure that the default connection directory exists, even though it is not needed. Instead, simply create the directory for the path to the connection file that we end up actually using. This introduces a slight change in behaviour in that if one specifies a connection file via the '-f' option and the given directory does not exist, it will be created instead of an error being generated.
1 parent 9b404d3 commit d92e430

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ipykernel/kernelapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp,
115115
# connection info:
116116
connection_dir = Unicode()
117117
def _connection_dir_default(self):
118-
d = jupyter_runtime_dir()
119-
ensure_dir_exists(d, 0o700)
120-
return d
118+
return jupyter_runtime_dir()
121119

122120
@property
123121
def abs_connection_file(self):
@@ -201,7 +199,9 @@ def init_connection_file(self):
201199
self.connection_file = filefind(self.connection_file, ['.', self.connection_dir])
202200
except IOError:
203201
self.log.debug("Connection file not found: %s", self.connection_file)
204-
# This means I own it, so I will clean it up:
202+
# This means I own it, and I'll create it in this directory:
203+
ensure_dir_exists(os.path.dirname(self.abs_connection_file), 0o700)
204+
# Also, I will clean it up:
205205
atexit.register(self.cleanup_connection_file)
206206
return
207207
try:

0 commit comments

Comments
 (0)