[pyar] [Aporte] Para los que estan escribiendo proyectos.

Angel Freire cuerty en gmail.com
Jue Oct 21 18:04:14 ART 2010


On Thu, Oct 21, 2010 at 5:52 PM, QliX=D! [aka EHB] <qlixed en gmail.com> wrote:
> 2010/10/21 QliX=D! [aka EHB] <qlixed en gmail.com>:
>> Pero entonces un close en python no asegura un flush? es dependiente
>> de la implementacion?.
>> Despertaron mi sherlock holmes....
>>
>> EHB
>
>
> Che me respondo a mi mismo:
> aca: http://svn.python.org/view/python/trunk/Modules/_io/fileio.c?view=markup
>
> siguiendo un toque el codigo, veo que:
>
> fileio_methods[] = {
>   [...]
> #endif
>    {"close",    (PyCFunction)fileio_close,        METH_NOARGS,  close_doc},
> [...]
>
> Luego:
>
> static PyObject *
> fileio_close(fileio *self)
> {
>   [...]
>    errno = internal_close(self);
>   [...]
>
> Y llegamos a:
>
> /* Returns 0 on success, -1 with exception set on failure. */
> static int
> internal_close(fileio *self)
> {
>   [...]
>            Py_BEGIN_ALLOW_THREADS
>            err = close(fd);
>            if (err < 0)
>                save_errno = errno;
>            Py_END_ALLOW_THREADS
>        [...]
>
> Que usa close(fd) que es el viejo y conocido close de C.
> Que segun tengo entendido flushea el buffer antes de cerrar el filedescriptor.
> Por lo tanto no deberia ser necesario hacer el os.system("sync"), debe
> existir algun otro problema por el cual te cuelga y vuelca el core...
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>

De la man page de sync: "Force changed blocks to disk, update the super block."

Muchos sistemas de archivos hacen trampa cuando uno hace un "sync" en
el file descriptor de archivo y no escriben a disco si no que cachean
y después hacen muchas escrituras juntas. reiserfs por ejemplo es muy
agresivo en cuanto a cachear antes de escribir, desconozco como se
comportan ext<2,3,4> pero imagino que deben tener algo similar.

Llamar a os.system("sync") es una forma de decirle al sistema
operativo "che, todos esos sistemas de archivos que tenes que pueden
llegar a estar haciéndome trampa y cacheando, deciles que no me jodan
y escriban físicamente al disco rígido". Tampoco garantiza nada, pero
es una protección mas.

-- 
http://blog.cuerty.com

"If you want to set off and go develop some grand new thing, you don't
need millions of dollars of capitalization. You need enough pizza and
Diet Coke to stick in your refrigerator, a cheap PC to work on and the
dedication to go through with it."
- John Carmack



More information about the pyar mailing list