[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2019-10-22 Thread STINNER Victor
STINNER Victor added the comment: > The problem is resolved if call PyGC_Collect() after PyDict_DelItemString(). > Is it expected to call PyGC_Collect() here? Yeah sadly, to handle such reference cycles, you have to trigger an explicit garbage collection. It doesn't sound like a bug to me.

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-22 Thread Jack Liu
Changes by Jack Liu : -- nosy: +pitrou ___ Python tracker ___ ___ Python-bugs-list

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-21 Thread Nick Coghlan
Nick Coghlan added the comment: To be entirely clear about what's going on, the reference cycle seen in the example arises for *any* module level function, even if it's completely empty: >>> def f(): ... pass ... >>> f.__globals__["f"] is f True The existence of that cycle will then keep

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-21 Thread Nick Coghlan
Nick Coghlan added the comment: The most likely relevant difference here is that Python 3.4+ no longer forcibly break cycles through the module globals when the module is deallocated: https://docs.python.org/dev/whatsnew/3.4.html#whatsnew-pep-442 Due to the implicit cycles created between

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-21 Thread Jack Liu
Jack Liu added the comment: @serhiy.storchaka, The reference counts before PyDict_DelItemString are same on Python 3.3, 3.5 and 3.6. Py_REFCNT(py_module)1 Py_REFCNT(py_dict)4 -- ___ Python tracker

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Please output Py_REFCNT(py_module) and Py_REFCNT(py_dict) before deleting the module from sys.modules. Is there a difference between 3.5 and 3.6? -- nosy: +serhiy.storchaka ___ Python tracker

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-20 Thread Jack Liu
Jack Liu added the comment: Looks to me, there is NO reference cycle on the Simple object in the python test code. Why needs to call PyGC_Collect() here? -- ___ Python tracker

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-20 Thread Josh Rosenberg
Josh Rosenberg added the comment: The fact that it's resolved by PyGC_Collect indicates there is a reference cycle somewhere. PyGC_Collect is just looking for cyclic garbage and breaking the cycles so it can be cleaned; it would happen eventually unless GC was explicitly disabled or the

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-20 Thread Jack Liu
Jack Liu added the comment: The problem is resolved if call PyGC_Collect() after PyDict_DelItemString(). Is it expected to call PyGC_Collect() here? -- ___ Python tracker

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-20 Thread Jack Liu
Jack Liu added the comment: I know there is a workaround to set the global variables to None at last in Python scripts. But my app just provide a framework for my customers to run python scripts. That means the workaround requires my customers to update their python scripts. That may make

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Jack Liu
Jack Liu added the comment: I wrote the test code as below. I also attached the files in attachment. Python = class Simple: def __init__( self ): print('Simple__init__') def __del__( self ):

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Jack Liu
Jack Liu added the comment: @eric.snow, Thank you for the replay. You understood right. I run this module as __main__ module, so there is no other modules to reference this module. And as I debugged, the ref count of this module became 0 after calling PyDict_DelItemString, but global variable

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Eric Snow
Eric Snow added the comment: To make sure I'm understanding: * you are using PyDict_DelItemString() on sys.modules * a module-level variable in the module is not getting cleaned up when the module is deleted from sys.modules * this worked in Python 3.3 but not in 3.5 It may help to have a

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Xiang Zhang
Changes by Xiang Zhang : -- nosy: +brett.cannon, eric.snow, ncoghlan ___ Python tracker ___

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Jack Liu
Jack Liu added the comment: I have a app loading python35.dll. Use python API PyImport_AddModule to run a py file. And use PyDict_DelItemString to delete the module. There is a global vailable in the py file. The global variable is not destroyed when calling PyDict_DelItemString to delete the

[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

2016-09-19 Thread Jack Liu
Changes by Jack Liu : -- components: +Extension Modules -Library (Lib) title: Python 3.5.1 C API, the global available available is not destroyed when delete the module -> Python 3.5.1 C API, the global variable is not destroyed when delete the module