[Python-Dev] RE: cloning iterators again

Guido van Rossum guido at python.org
Tue Oct 28 13:34:09 EST 2003

> Ok on this point, the question was whether (the error-checking obfuscated
> equivalent of)
>    PyObject *m = PyImport_ImportModule("copy");
>    PyObject_CallMethod(m, "deepcopy", x, memo);
> should be done inside a built-in __deepcopy__ implementation.  It looks like
> it will make a hell of a lot of quite slow calls to PyImport_ImportModule()  
> for structures like lists of generators, which is the kind of structure you
> are interested in when you deepcopy generators.

Yeah, you should ideally be able to cache the resuls of the import,
except then your code wouldn't work when theer are multiple
interpreters.  Maybe using

  PyObject *modules = PySys_GetObject("modules");
  PyObject *m = PyDict_Lookup(modules, "copy");

would be faster?  PySys_GetObject() doesn't waste much time. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list