Amaury Forgeot d'Arc added the comment:

The NoneType that fails is in typeobject.c:
   _PyObject_CallMethodId(copyreg, &PyId__slotnames, "O", cls);

The error here is that copyreg comes from a cached reference to the module, 
stored in a static variable (cached_copyreg_module).  When the interpreter 
shuts down the first time, all the module members are set to None... but the 
reference is kept forever.

This variable should be reset, and reloaded (with a fresh module from the new 
interpreter) the next time it's used.
I added a call to _PyType_Fini() in Py_EndInterpreter, this fixes the given 
example.

Two sets of questions though:

- There are many of these _Fini functions, called in Py_Finalize. Which ones 
should we call in Py_EndInterpreter? and why? Maybe this PyType_Fini() is not a 
_Fini, but should be renamed PyType_EndInterpreter?

- one copyreg for multiple interpreters... this looks wrong: each interpreter 
has its own list of modules, but copyreg.__globals__ belongs to only one...
  A good solution would be to cache the copyreg module in the 
PyInterpreterState (it already has codec_search_cache). Or use 
PyImport_GetModuleDict()

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19088>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to