El mié., 28 nov. 2018 a las 9:43, Chema Cortes (<pych...@gmail.com>)
escribió:

>
>
> El mar., 27 nov. 2018 a las 8:13, Angel Lis (<anlis...@gmail.com>)
> escribió:
>
>> Hola Jose,
>> el problema que describes es la razon de por que existe el metodo
>> copy.copy() y copy.deepcopy()
>> de la documentacion:
>>
>> https://docs.python.org/2.7/library/copy.html
>>
>> """
>>
>>    - A *shallow copy* constructs a new compound object and then (to the
>>    extent possible) inserts *references* into it to the objects found in
>>    the original.
>>    - A *deep copy* constructs a new compound object and then,
>>    recursively, inserts *copies* into it of the objects found in the
>>    original.
>>
>>
>> """
>>
>> Y para el objeto logging:
>>
>>
>> https://docs.python.org/2.7/library/logging.html?highlight=logging#thread-safety
>> """
>> The logging module is intended to be thread-safe without any special
>> work needing to be done by its clients. It achieves this though using
>> threading locks; there is one lock to serialize access to the module’s
>> shared data, and each handler also creates a lock to serialize access to
>> its underlying I/O.
>> """
>>
>> En este caso, probablemente deberas usar un copy() en vez de deepcopy.
>> Espero haberte ayudado.
>>
>>
> El módulo 'logging' usa locks para bloquear los hilos que no es
> conveniente duplicar, de ahí que saque el error.
>
> Aún así, se puede aprovechar el funcionamiento que tiene 'deepcopy' para
> evitar duplicar componentes que ya ha copiado en su intento de replicar
> toda la estructura de un objeto. Tiene un segundo argumento para pasarle el
> diccionario con el que "*memoizar*" los componentes ya duplicados. Si a
> este argumento añadimos aquellos componentes que no queremos duplicar ya
> debería funcionar:
>
> c = C()
> mem = { id(c.log):  c.log }
> x = copy.deepcopy(c)
>
> id(c) == id(x)  # False
> id(c.log) == id(x.log)  # True
>
>
Me había dejado el diccionario como segundo argumento:

c = C()
mem = { id(c.log):  c.log }
x = copy.deepcopy(c, mem)


-- 
Hyperreals *R  "Quarks, bits y otras criaturas infinitesimales":
https://blog.ch3m4.org
Buscador Python Hispano: http://busca.ch3m4.org
<https://blog.ch3m4.org/pages/busqueda-python-es/>
_______________________________________________
Python-es mailing list
Python-es@python.org
https://mail.python.org/mailman/listinfo/python-es

Responder a