On Wed Aug 05 14:10:26 2009,
https://www.google.com/accounts/o8/id?id=AItOawlexYTVVJ0Oz98YNS01DA5avM0engOM7NU
wrote:
Show quoted text> On Wed Aug 05 08:15:11 2009, NINE wrote:
> > On Tue Jul 28 15:49:44 2009,
> >
>
https://www.google.com/accounts/o8/id?id=AItOawlexYTVVJ0Oz98YNS01DA5avM0engOM7NU
Show quoted text> > wrote:
> > > Inline::Python::py_eval(<<'END');
> > >
> > > from test import Test
> > >
> > > t = Test()
> > >
> > > END
> > >
> > > And I execute each one, you can see that executing python directly
> > > results in the destructor being called, but in perl, the
> destructor
> > is
> > > never executed:
> >
> > It seems like objects don't get destroyed if the variables are in
> the
> > Python __main__ namespace. They do get destroyed (and the Python
> > destructors executed) if they are inside functions, passed to perl,
> > etc. So I'd think, that it's not so much a problem, since those
> > objects
> > would only get destroyed on program exit anyway. Do you need your
> > destructors called in that case? If, I'll try to investigate, what's
> > going on and if I can make it work.
>
> The destructors are important to run to release external resources,
> but
> I don't necessarily need them to be in __main__. My issues must be
> occuring for another reason. I've verified that they do in fact get
> run
> if they cross into perl, which is where they're all handled in my
> code,
> so I personally don't really need this fixed. Thanks.
I have verified that Inline::Python also does not handle cyclic garbage
collection:
===== test.pl =====
use strict;
use warnings;
use Inline::Python;
Inline::Python::eval_python("import destructor_test");
my $obj = Inline::Python::py_call_function("destructor_test", "get_object");
my $other = Inline::Python::py_call_function("destructor_test",
"get_object", $obj);
Inline::Python::py_call_method($obj, "attach", $other);
===== destructor_test.py =====
def get_object(other=None):
c = Class()
c.attach(other)
return c
class Class(object):
def __del__(self):
print "Destructor"
def attach(self, other):
self.other = other
==============================
Running test.pl prints no output, therefore the python destructor is not
getting called. If I remove the calls to "attach", both are deleted
correctly.