##// END OF EJS Templates
kernel app cleans up connection files that it wrote
MinRK -
Show More
@@ -16,6 +16,7 b' Authors'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # Standard library imports
18 # Standard library imports
19 import atexit
19 import json
20 import json
20 import os
21 import os
21 import sys
22 import sys
@@ -95,6 +96,7 b' class KernelApp(BaseIPythonApplication):'
95 heartbeat = Instance(Heartbeat)
96 heartbeat = Instance(Heartbeat)
96 session = Instance('IPython.zmq.session.Session')
97 session = Instance('IPython.zmq.session.Session')
97 ports = Dict()
98 ports = Dict()
99 _full_connection_file = Unicode()
98
100
99 # inherit config file name from parent:
101 # inherit config file name from parent:
100 parent_appname = Unicode(config=True)
102 parent_appname = Unicode(config=True)
@@ -165,6 +167,8 b' class KernelApp(BaseIPythonApplication):'
165 fname = filefind(self.connection_file, ['.', self.profile_dir.security_dir])
167 fname = filefind(self.connection_file, ['.', self.profile_dir.security_dir])
166 except IOError:
168 except IOError:
167 self.log.debug("Connection file not found: %s", self.connection_file)
169 self.log.debug("Connection file not found: %s", self.connection_file)
170 # This means I own it, so I will clean it up:
171 atexit.register(self.cleanup_connection_file)
168 return
172 return
169 self.log.debug(u"Loading connection file %s", fname)
173 self.log.debug(u"Loading connection file %s", fname)
170 with open(fname) as f:
174 with open(fname) as f:
@@ -190,6 +194,16 b' class KernelApp(BaseIPythonApplication):'
190 write_connection_file(cf, ip=self.ip, key=self.session.key,
194 write_connection_file(cf, ip=self.ip, key=self.session.key,
191 shell_port=self.shell_port, stdin_port=self.stdin_port, hb_port=self.hb_port,
195 shell_port=self.shell_port, stdin_port=self.stdin_port, hb_port=self.hb_port,
192 iopub_port=self.iopub_port)
196 iopub_port=self.iopub_port)
197
198 self._full_connection_file = cf
199
200 def cleanup_connection_file(self):
201 cf = self._full_connection_file
202 self.log.debug("cleaning up connection file: %r", cf)
203 try:
204 os.remove(cf)
205 except (IOError, OSError):
206 pass
193
207
194 def init_connection_file(self):
208 def init_connection_file(self):
195 if not self.connection_file:
209 if not self.connection_file:
General Comments 0
You need to be logged in to leave comments. Login now