Message196507
'tempfile.NamedTemporaryFile' returns an instance of '_TemporaryFileWrapper' that wraps the created file object. The wrapper object implements '__getattr__' and we end up with a situation like the following simplified example where the wrapper gets destroyed before the looked up method is called:
$ cat test.py
class S(object):
def __init__(self):
print("S.__init__") def __del__(self): print("S.__del__")
def foo(self):
print("S.foo")
class T(object):
def __init__(self, s):
self.s = s
print("T.__init__")
def __getattr__(self, name):
s = self.__dict__['s']
a = getattr(s, name)
print("__getattr__('%s')" % name)
if not isinstance(a, int):
setattr(self, name, a)
return a
def __del__(self):
print("T.__del__")
T(S()).foo()
$ ./python test.py
S.__init__
T.__init__
__getattr__('foo')
T.__del__
S.foo
S.__del__ |
|
Date |
User |
Action |
Args |
2013-08-30 03:21:59 | meador.inge | set | recipients:
+ meador.inge, georg.brandl, ncoghlan, vstinner, r.david.murray, serhiy.storchaka, jort.bloem |
2013-08-30 03:21:58 | meador.inge | set | messageid: <1377832918.98.0.865596493779.issue18879@psf.upfronthosting.co.za> |
2013-08-30 03:21:58 | meador.inge | link | issue18879 messages |
2013-08-30 03:21:58 | meador.inge | create | |
|