##// END OF EJS Templates
avoid import of nearby temporary with %edit...
Matthias BUSSONNIER -
Show More
@@ -572,6 +572,7 b' class InteractiveShell(SingletonConfigurable):'
572 572
573 573 # Temporary files used for various purposes. Deleted at exit.
574 574 self.tempfiles = []
575 self.tempdirs = []
575 576
576 577 # Keep track of readline usage (later set by init_readline)
577 578 self.has_readline = False
@@ -3003,15 +3004,19 b' class InteractiveShell(SingletonConfigurable):'
3003 3004 def mktempfile(self, data=None, prefix='ipython_edit_'):
3004 3005 """Make a new tempfile and return its filename.
3005 3006
3006 This makes a call to tempfile.mktemp, but it registers the created
3007 filename internally so ipython cleans it up at exit time.
3007 This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),
3008 but it registers the created filename internally so ipython cleans it up
3009 at exit time.
3008 3010
3009 3011 Optional inputs:
3010 3012
3011 3013 - data(None): if data is given, it gets written out to the temp file
3012 3014 immediately, and the file is closed again."""
3013 3015
3014 filename = tempfile.mktemp('.py', prefix)
3016 dirname = tempfile.mkdtemp(prefix=prefix)
3017 self.tempdirs.append(dirname)
3018
3019 handle, filename = tempfile.mkstemp('.py', prefix, dir=dirname)
3015 3020 self.tempfiles.append(filename)
3016 3021
3017 3022 if data:
@@ -3164,13 +3169,19 b' class InteractiveShell(SingletonConfigurable):'
3164 3169 # history db
3165 3170 self.history_manager.end_session()
3166 3171
3167 # Cleanup all tempfiles left around
3172 # Cleanup all tempfiles and folders left around
3168 3173 for tfile in self.tempfiles:
3169 3174 try:
3170 3175 os.unlink(tfile)
3171 3176 except OSError:
3172 3177 pass
3173 3178
3179 for tdir in self.tempdirs:
3180 try:
3181 os.rmdir(tdir)
3182 except OSError:
3183 pass
3184
3174 3185 # Clear all user namespaces to release all references cleanly.
3175 3186 self.reset(new_session=False)
3176 3187
General Comments 0
You need to be logged in to leave comments. Login now