Trading Bots vs Arbitrage Bots
Instrucciones
El objetivo es montar un sistema que permita ejecutar un script Python sin interrupciones, independientemente de excepciones, reinicios o cualquier otro tipo de incidencia.
Esta solución se basa en definir un proceso cron que ejecuta un script (el que se adjunta) que determina si el script Python está ejecutándose y, en caso contrario, lo lanza de nuevo.
Esta solución se basa en definir un proceso cron que ejecuta un script (el que se adjunta) que determina si el script Python está ejecutándose y, en caso contrario, lo lanza de nuevo.
import sys
#Get the process id of this process
pid = os.getpid()
#Get the name of this script, as passed to the Python interpreter
myname = sys.argv[0]
#Run a ps command that includes the command lines of processes
ps = os.popen('ps --no-headers -elf|fgrep %s' % myname)
#Search for any processes that are running python and this script. We check for
#python so that we don't bomb when, for example, someone's editing this script
#in vi.
for p in ps:
if p.find('python')>-1 and p.find(myname)>-1:
#If the pid of the process we've found is not the same as our pid,
#then another instance is running.
otherpid = int(p.split()[3])
if otherpid <> pid: sys.exit()
ps.close()
Cŕeditos
Script desarrollado por Ben Last.
Notas Adicionales
Para más información consultar http://www.livejournal.com/users/benlast/21039.html.