Ich habe ein Python-Skript im Hintergrund mit nohup ./myprogram.py 1>console.out &
ausgeführt. Das Programm protokolliert ständig in einer Protokolldatei und die Verarbeitung ist lang. Nach der Ausführung für 2 Tage (Samstag und Sonntag) Ich seheder Grund für das Beenden meines Programms
# myprogram and myprogram2 are both running in background
# myprogram2 clearly has finished
[1] + 25159 exit 1 nohup ./myprogram.py 1>console.out &
[2] + 25442 done nohup ./myprogram2.py 1>console2.out &
Das Protokoll für myprogram
2016-05-27 16:55:06 - sources.edf - INFO - processing day 1 ...
2016-05-27 16:55:06 - sources.edf - INFO - processing day 2 ...
...
2016-05-27 16:55:06 - sources.edf - INFO - processing day n ...
und gestoppt (es sollte n + 1 und mehr).
Leider habe ich nur schon auf console.out überschrieben (also dump um es zu überschreiben bevor ich es mir selbst angesehen habe ... aber ich ging vom Tag n weiter und scheint das Programm ohne Fehler/Ausnahme laufen zu lassen)
Ich weiß, dass diese Beschreibung ein bisschen oder einfach zu vage ist, um irgendeinen Grund für diesen Ausgang aufzuzeigen. Ich muss nur eine Ahnung davon haben. Ich bin nicht völlig neu, aber mir fehlt es an Erfahrung. Also jede mögliche Schätzung wird geschätzt.
Der vereinfachte Quellcode:
import os
import sys
import logging
import logging.config as lconfig
from optparse import OptionParser
from contextlib import closing
from datetime import datetime, timedelta
from collections import defaultdict
import psycopg2
from configobj import ConfigObj
if __name__ == "__main__":
## setup optparser and parse argvs and return opts and args
conf = ConfigObj(opts.config, list_values=False)[args[0]]
__import__(conf["module"])
## myprogram and myprogram2 is running the same source code
## same module. only the data is different
## source will provide Mapper and iterator as APIs
source = sys.modules[conf["module"]]
## extract start and end date, configure log
# set up regions info and mapper
## connect to db and read countries and exchange list
with closing(psycopg2.connect(conf["dsn"])) as db:
cursor = db.cursor()
regions = source.setup_region(conf['Regions'], cursor)
## find all wanted exchanges: (exch, region)
exchanges = source.setup_exchanges(conf['Exchanges'], cursor)
mapper = source.Mapper(exchanges, cursor, conf)
iterator = source.iterator(conf, start, end)
logger = logging.getLogger()
logger.info('START')
with regions:
for filename, raw_rec in iterator:
logger.info('Processing file {0}'.format(filename)
try:
record = source.Record(filename, raw_rec)
except Exception as e:
logger.warn("record parsing error: %s" % e)
continue
stks = mapper.find(record)
if not stks:
continue
regs = defaultdict(set)
for stk in stks:
regnm = exchanges[stk[2]]
regs[regnm].add(stk)
for reg,secs in regs.iteritems():
info = regions[reg]
outf = info.get_file(record.get_tm())
source.output(outf, record, secs, info.tz, conf)
logger.info('END')
Das Protokoll gestoppt genauso Prccessing einige Datei ...
starten Können Sie myprogram.py posten und myprogram2.py? – SilentMonk
@SilentMonk, es ist nur eine große zu lange hier zu posten. Ich werde versuchen, –
Log * stderr * ('2>') zu vereinfachen und wir werden es wissen. – pacholik