Python 3.5.1 C API, the global available available is not destroyed when delete the module

dl l ldlchina at gmail.com
Tue Sep 20 23:47:11 EDT 2016


Thank you all for the help.

I found the problem is resolved if call PyGC_Collect() after
PyDict_DelItemString(). Is it expected to call PyGC_Collect() here for
Python 3.5 which is not needed for Python 3.3?

2016-09-20 16:01 GMT+08:00 Chris Angelico <rosuav at gmail.com>:

> On Tue, Sep 20, 2016 at 4:19 PM, dl l <ldlchina at gmail.com> wrote:
> > Yes, it's a workaround to set the global variables to None. But My app
> just
> > provide a framework for my customers to run python scripts. That's means
> > the workaround requires my customers to update their python scripts. That
> > may make them unhappy :(. Is there a workaround in my code C++ side to
> call
> > Python C APIs to resolve the memory leak issue?
> >
>
> Python's import system is fundamentally not designed for what I
> believe is your use-case here, of running potentially-edited user
> code. Instead, I suggest keeping 'import' for stable modules that
> don't get updated without restarting the process, and for the more
> dynamic code, build something using exec (or PyRun_StringFlags, which
> I believe is the C equivalent). Object lifetimes will then be entirely
> under your control.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list