[pyar] Mejor forma de generar pid files?

Eka (Esteban Feldman) ekagaurangadas en gmail.com
Lun Dic 13 11:22:55 ART 2010


2010/12/13 Andrés Gattinoni <andresgattinoni en gmail.com>

> 2010/12/13 Eka (Esteban Feldman) <ekagaurangadas en gmail.com>:
> > Gente, en estos momentos hago lo siguiente
> >
> > open(pid_file, 'w').write(str(os.getpid()))
> > ...
> > os.unlink(pid_file)
> >
> > hay alguna forma mejor de hacer esto? la otra es que pasaria si rompese
> > antes de borrar el pid file.
> >
>
> Googleando encontré esto [0]. Hace lo mismo que vos. Pero le agrega
> una cosa interesante que al menos yo no conocía.
>
> import atexit
>
> [...]
> atexit.register(self.delpid)
> [...]
> def delpid(self):
>                os.remove(self.pidfile)
>
> [0]
> http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
> _______________________________________________
> 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/
>

Andres: de la docu: Note: the functions registered via this module are not
called when the program is killed by a signal not handled by Python, when a
Python fatal internal error is detected, or when
os._exit()<http://docs.python.org/library/os.html#os._exit>is called.

Mi idea es, cuando se ejecuta de nuevo el programa, ver si existe el
archivo, leer el pid y ver si realmente esta corriendo, dado que pudo no
haber borrado el pid file.

Eso parece bien? Uso Popen con ps?

-- 
Chant Hare Krishna and Be Happy

Eka
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20101213/3b7c69f4/attachment.html>


More information about the pyar mailing list