Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/12/2014, 21:20
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: releer fichero en demonio phyton

Algunas sugerencias:

Haz intentando crear un tarea programada usando cron?

Puedes usar watchdog para usar ejecutar comandos cuando exista un cambio en un archivo.

Con respecto a tu script original, has intentado meterlo en un ciclo y correr este proceso demonizado?

Código Python:
Ver original
  1. delay = 360
  2. while True:
  3.     tempout = open("/home/pi/projects/tempo1.txt")
  4.     tempout1 = tempout.read(8)
  5.     tempout1 =float(tempout1)* 1.8 + 32
  6.     tempout.close()
  7.     #print tempout
  8.  
  9.     # upload data to mi_web
  10.     try:
  11.         conn = httplib.HTTPConnection("miweb.com")
  12.         path = "/blablalba/blabalba?ID=xxxxxxxxx&PASSWORD=clave_pass&dateutc=" + str(datetime.utcnow().isoformat()) + "&humidity=" + str(humidity) + "&tempf=" + str(tempout1) + "&baromin=" + str(press1) + "&softwaretype=status=updateraw"
  13.         conn.request("GET", path)
  14.         res = conn.getresponse()
  15.     print path
  16.  
  17.  
  18.     # checks whether there was a successful connection (HTTP code 200 and content of page contains "success")
  19.         if ((int(res.status) == 200) & ("success" in res.read())):
  20.                 print "%s - Successful Upload\nTemp: %.1f F, Humidity: %.1f %%\nNext upload in %i seconds\n" % (str(datetime.now()), temp, humidity, delay)
  21.         else:
  22.                 print "%s -- Upload not successful, check username, password, and formating.. Will try again in %i seconds" % (str(datetime.now()), delay)
  23.     except IOError as e: #in case of any kind of socket error
  24.         print "{0} -- I/O error({1}): {2} will try again in {3} seconds".format(datetime.now(), e.errno, e.strerror, delay)
  25.  
  26.     # Wait before re-uploading data
  27.     time.sleep(delay)

Código BASH:
Ver original
  1. nohup python myscript.py