【发布时间】:2013-11-29 22:51:56
【问题描述】:
所以,
有问题的代码如下,但是它也可以随机发生在其他脚本上(我认为错误不在代码中)
由于某种原因,它有时完全随机地崩溃并弹出“pythonw.exe 已停止工作”,可能是在 5 小时、24 小时或 5 天后...我无法弄清楚它为什么会崩溃。
from datetime import date, timedelta
from sched import scheduler
from time import time, sleep, strftime
import random
import traceback
s = scheduler(time, sleep)
random.seed()
def periodically(runtime, intsmall, intlarge, function):
currenttime = strftime('%H:%M:%S')
with open('eod.txt') as o:
eod = o.read().strip()
if eod == "1":
EOD_T = True
else:
EOD_T = False
while currenttime >= '23:40:00' and currenttime <= '23:59:59' or currenttime >= '00:00:00' and currenttime <= '11:30:00' or EOD_T:
if currenttime >= '23:50:00' and currenttime <= '23:59:59':
EOD_T = False
currenttime = strftime('%H:%M:%S')
print currenttime, "Idling..."
sleep(10)
open("tca.txt", 'w').close
open("tca.txt", 'w').close
runtime += random.randrange(intsmall, intlarge)
s.enter(runtime, 1, function, ())
s.run()
def execute_subscripts():
st = time()
print "Running..."
try:
with open('main.csv'):
CSVFile = True
except IOError:
CSVFile = False
with open('eod.txt') as eod:
eod = eod.read().strip()
if eod == "1":
EOD_T = True
else:
EOD_T = False
if CSVFile and not EOD_T:
errors = open('ERROR(S).txt', 'a')
try:
execfile("SUBSCRIPTS/test.py", {})
except Exception:
errors.write(traceback.format_exc() + '\n')
errors.write("\n\n")
errors.close()
print """ %.3f seconds""" % (time() - st)
while True:
periodically(15, -10, +50, execute_subscripts)
有谁知道我如何找出它崩溃的原因或知道为什么并知道修复它的方法?
谢谢
- 海福克斯
【问题讨论】:
-
顺便问一下,您使用的是哪个版本的 Python 2.7?并且,如果可以,请尝试迁移到最新发布的版本。
-
我正在运行 2.7.5 版
标签: python python-2.7