##// END OF EJS Templates
Fix warning when running IPython.kernel tests...
Thomas Kluyver -
Show More
@@ -32,15 +32,30 b' except ImportError:'
32 def __enter__(self):
32 def __enter__(self):
33 return self.name
33 return self.name
34
34
35 def cleanup(self):
35 def cleanup(self, _warn=False):
36 if not self._closed:
36 if self.name and not self._closed:
37 self._rmtree(self.name)
37 try:
38 self._rmtree(self.name)
39 except (TypeError, AttributeError) as ex:
40 # Issue #10188: Emit a warning on stderr
41 # if the directory could not be cleaned
42 # up due to missing globals
43 if "None" not in str(ex):
44 raise
45 print("ERROR: {!r} while cleaning up {!r}".format(ex, self,),
46 file=_sys.stderr)
47 return
38 self._closed = True
48 self._closed = True
49 if _warn:
50 self._warn("Implicitly cleaning up {!r}".format(self),
51 ResourceWarning)
39
52
40 def __exit__(self, exc, value, tb):
53 def __exit__(self, exc, value, tb):
41 self.cleanup()
54 self.cleanup()
42
55
43 __del__ = cleanup
56 def __del__(self):
57 # Issue a ResourceWarning if implicit cleanup needed
58 self.cleanup(_warn=True)
44
59
45
60
46 # XXX (ncoghlan): The following code attempts to make
61 # XXX (ncoghlan): The following code attempts to make
@@ -124,9 +139,9 b' class TemporaryWorkingDirectory(TemporaryDirectory):'
124 _os.chdir(self.name)
139 _os.chdir(self.name)
125
140
126
141
127 def cleanup(self):
142 def cleanup(self, _warn=False):
128 #Revert to old cwd.
143 #Revert to old cwd.
129 _os.chdir(self.old_wd)
144 _os.chdir(self.old_wd)
130
145
131 #Cleanup
146 #Cleanup
132 super(TemporaryWorkingDirectory, self).cleanup()
147 super(TemporaryWorkingDirectory, self).cleanup(_warn=_warn)
General Comments 0
You need to be logged in to leave comments. Login now