This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author meador.inge
Recipients georg.brandl, jort.bloem, meador.inge, ncoghlan, r.david.murray, serhiy.storchaka, vstinner
Date 2013-08-30.03:21:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377832918.98.0.865596493779.issue18879@psf.upfronthosting.co.za>
In-reply-to
Content
'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__
History
Date User Action Args
2013-08-30 03:21:59meador.ingesetrecipients: + meador.inge, georg.brandl, ncoghlan, vstinner, r.david.murray, serhiy.storchaka, jort.bloem
2013-08-30 03:21:58meador.ingesetmessageid: <1377832918.98.0.865596493779.issue18879@psf.upfronthosting.co.za>
2013-08-30 03:21:58meador.ingelinkissue18879 messages
2013-08-30 03:21:58meador.ingecreate