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