congosto / t-hoarder

T-Hoarder platform stores long-term tweets (years) by thematic lines and it automatically processes them in three-axis: time, space, and relevance.
GNU General Public License v3.0
48 stars 17 forks source link

El script se detiene inesperadamente #8

Open numeroteca opened 7 years ago

numeroteca commented 7 years ago

A veces se me interrumpe el script, pero no sé por qué razón.

@congosto ¿te ha pasado antes?

Me ha dado este error:

~/t-hoarder/store$ Traceback (most recent call last):
  File "/home/numeroteca/t-hoarder/scripts/tweet_streaming.py", line 303, in <module>
    main()
  File "/home/numeroteca/t-hoarder/scripts/tweet_streaming.py", line 299, in main
    stream.filter(follow_list, track_list,False,locations_list_int)
  File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 445, in filter
    self._start(async)
  File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 361, in _start
    self._run()
  File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 294, in _run
    raise exception
requests.packages.urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read, 695 more expected)', IncompleteRead(0 bytes read, 695 more expected))
grep -vc '^$' *^C
[3]+  Exit 1                  tweet_streaming.py $HOME rita my_app.key numeroteca.key --words words.txt  (wd: ~/t-hoarder/store/datos_rita)
(wd now: ~/t-hoarder/store)
congosto commented 7 years ago

El streaming puede dar errores por muchos motivos o pararse. Por ese motivo aconsejo lanzarlo desde una shell que lo rearranque si se para. Algo así:

#!/bin/bash
# shell script para llamar indefinidamente al streaming api y que espere 10 segundos despues de una caída

if [ $# -ne 5 ]
then
   echo "uso: streaming_persistente   script + parametros"
      exit 1
fi
while true
 do
  echo ejecuto comando $1 $2 $3 $4 $5
  $1 $2 $3 $4 $5
  sleep 10
done

El comando se debe arrancar en background poniendole al final un &

También aconsejo poner en un shell script todos los comandos que arrancan los streamings e invocarlo desde el fichero /etc/rc.local. de esta manera al reiniciarse un servidor, se rearrancan todos los scripts

numeroteca commented 7 years ago

No me queda claro cómo sería el script y desde dónde ejecutarlo ¿me puedes poner un ejemplo real? ¡Gracias!

¿Sabemos por qué falla tanto el script del streaming?

congosto commented 7 years ago

Si el script que arranca indefinidamente un streaming se llamara streaming_persistente se invocaría así:

streaming_persistente tweet_streaming.py root experiment app_keys user_keys --words words.txt &

Cerciórate que solo hay un usuario por streaming. Aún así, los fallos de comunicaciones son intermitentes y dependen del estado de la infraestructura de Twitter o de la red dónde se encuentra el servidor, Ten en cuenta que es un socket está funcionando indefinidamente y expuesto a cualquier incidencia de la red. Por ejemplo en el streamning de bankia que tengo en la uc3m el día 14 de noviembre hubo bastantes cortes a las 11:20 y otro a las 19, sin embargo del 15 hasta hoy solo hay un corte a las 7:00 am, un corte propagado para resetear los streaming (reset preventivo)

====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:25:36.215960
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:25:51.283075
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:26:11.357068
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:26:31.432870
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:26:51.510102
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:27:06.578062
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:27:26.655750
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:27:46.731146
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:28:06.800756
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:28:26.874860
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:28:41.942212
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:29:02.019883
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:29:22.097112
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:29:42.176392
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:29:57.243191
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:30:17.317187
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:30:37.388233
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:30:57.468139
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:31:17.542420
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:31:37.613097
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 11:31:57.689067
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-14 19:13:42.705435
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-15 07:00:11.108696
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-16 07:00:11.899815
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-17 07:00:11.480383
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-18 07:00:11.442825
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-19 07:00:11.653182
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-20 07:00:12.044749
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-21 07:00:11.555322
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-22 07:00:11.567470
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-23 07:00:11.167658
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-11-24 07:00:11.184399
numeroteca commented 7 years ago

Gracias por la explicación. Vamos a ello:

He creado el archivo streaming_persistente en el directorio /scripts/. Le he otorgado permisos de ejecución.

Luego desde /store/datos_rita/he lanzado este script:

streaming_persistente tweet_streaming.py root rita app_keys user_keys --words words.txt &

No me funciona.

También he lanzado desde /store/datos_rita/ el script de bash (que previamente he copiado a este directorio). He usado el script que uso siempre de tweet_streaming pero lo he precedido de streaming_persistente:

./streaming_persistente tweet_streaming.py $HOME rita my_app.key numeroteca.key --words words.txt & Tampoco me funciona.

¿sugerencias?

congosto commented 7 years ago

Debiera funcionar

./streaming_persistente tweet_streaming.py $HOME rita my_app.key numeroteca.key --words words.txt &

lo miro

congosto commented 7 years ago

sorry el scripts es

hay 7 parámetros



El script debe ser así

#!/bin/bash
# shell script para llamar indefinidamente al streaming api y que espere 10 segundos despues de una caída

if [ $# -ne 7 ]
then
   echo "uso: streaming_persistente   script + parametros"
      exit 1
fi
while true
 do
  echo ejecuto comando $1 $2 $3 $4 $5 $6 $7
  $1 $2 $3 $4 $5 $6 $7
  sleep 10
done

pero me está dando el error 404
congosto commented 7 years ago

Lo probé y funciona bien.

Inténtalo tu a ver si te va bien

Como los streaming se puede quedar colgados con el tiempo, por esto es muy sano hacer un reset preventivo poniendo esta línea en el crontab (crontab -e)

Te lo pongo en modo imagen porque el wiki me quita comillas imagen

Esta línea mata todos los streamings arrancados a la 7 de la mañana. Como los streaming se arrancan con el script persiatente tras 10 segundos se vuelven a rearracar.

numeroteca commented 7 years ago

Ya me he instalado el comando en crontab -e.

Tras ejecuar:

./streaming_persistente tweet_streaming.py $HOME tarjetasblack my_app.key numeroteca.key --words words.txt &

Y luego:

ps -e -o pid,args |grep streaming

Me salen estos dos streaming corriendo ¿es correcto?

11103 /bin/bash ./streaming_persistente tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt 11104 /usr/bin/python /home/numeroteca/t-hoarder/scripts/tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt 11163 grep --color=auto streaming

congosto commented 7 years ago

Perfecto, eso es lo que debe salir.

Con el reset preventivo se mata el proceso 1104 /usr/bin/python /home/numeroteca/t-hoarder/scripts/tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt Que se rearranca 10 segundos después con el proceso 11103 /bin/bash ./streaming_persistente tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt

numeroteca commented 7 years ago

Pues no sé qué pasa. Las últimas veces que he vuelto a entrar el server o bien los dos procesos estaban caídos o sólo se mantenía uno de ellos (streaming_persistente). En cualquiera de los casso se había parado de recopilar datos. ¿qué puede ser?

congosto commented 7 years ago

el log tiene estos rearranques. Pondré más información en el log para saber por qué se cae el socket

====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  starting at 2016-12-08 01:13:48.687637
---------------->An error has occured! Status code = 406 at 2016-12-08 01:13:49.392530
---------------->An error has occured! Status code = 406 at 2016-12-08 01:13:55.063650
---------------->An error has occured! Status code = 406 at 2016-12-08 01:14:05.704151
---------------->An error has occured! Status code = 406 at 2016-12-08 01:14:26.314102
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-08 01:15:27.892429
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-08 01:16:41.741914
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-08 01:45:48.733464
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-08 01:49:49.091174
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-08 02:06:17.346383
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-09 02:41:21.653604
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-09 02:42:17.780764
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-09 12:51:45.435111
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt  remaining at 2016-12-09 20:33:38.021138
congosto commented 7 years ago

Debe ser sel servidor de la UOC porque en streaming que tengo en la uc3m de bankia solo se ha retesado con el reset preventivo

====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-01 07:00:11.207600
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-02 07:00:11.848081
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-03 07:00:11.323082
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-04 07:00:11.590623
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-05 07:00:11.173577
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-06 07:00:11.590224
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-07 07:00:11.382770
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-08 07:00:12.069793
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-09 07:00:11.530298
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt  remaining at 2016-12-10 07:00:11.751828