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