随机“pythonw.exe已停止工作”崩溃
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了随机“pythonw.exe已停止工作”崩溃,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3219字,纯文字阅读大概需要5分钟。
内容图文
![随机“pythonw.exe已停止工作”崩溃](/upload/InfoBanner/zyjiaocheng/804/576125bdaca74947a1e60b9752a783ee.jpg)
所以,
有问题的代码如下,但它也可以随机发生在其他脚本上(我不认为错误在于代码)
出于某种原因,它完全随机地崩溃并弹出“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)
有谁知道我怎么能找出它为什么崩溃或知道原因并知道解决方法?
谢谢
– Hyflex
解决方法:
我不知道,但它可能与两行有关:
open("tca.txt", 'w').close
那些没有做你打算做的事情:他们把文件保持打开状态.您需要调用close方法(不仅仅是检索它):
open("tca.txt", 'w').close()
^^
但那可能不是它. CPython会在变为垃圾时自动关闭文件对象(在这种情况下立即发生 – 一旦语句结束,refcount就会命中0).
也许你应该转移到Linux系统;-)
想法:是否有可能用python.exe运行它,从DOS框(cmd.exe)你打开并忽略?调试pythonw.exe死机的一个大问题是,没有控制台窗口可以显示可能弹出的任何错误消息.
这引出了另一个问题:这条线在做什么?
print "Running..."
如果你在pythonw.exe下运行,你永远不会看到它,对吧?这可能会导致问题,具体取决于您正在运行的Python和Windows的版本.标准输入和标准输出实际上并不存在,在pythonw下,我记得当向sys.stdout(打印使用)写入“太多”数据时,向Microsoft库追踪一个神秘的pythonw.exe死亡.
一种说法:如果你在python.exe下运行,而不是从DOS框运行,它运行一年而不会崩溃,这可能是原因;-)
例
这是一个简单的程序:
i = 0
while 1:
i += 1
with open("count.txt", "w") as f:
print >> f, i
print "hi!"
在32位Windows Vista下使用Python 2.7.6,它具有完全不同的行为,具体取决于是否使用python.exe或pythonw.exe来运行它.
在python.exe下:
C:\Python27>python yyy.py
hi!
hi!
hi!
hi!
hi!
hi!
hi!
hi!
hi!
hi!
hi!
...
这种情况一直持续下去,而且count.txt中的值不断增加.但:
C:\Python27>pythonw yyy.py
C:\Python27>
也就是说,没有可见的输出.这是预期的:pythonw将其程序与控制台窗口断开连接.
很短的时间后,pythonw.exe静静地死了(使用任务管理器看到这一点) – 消失得无影无踪.在那时候:
C:\Python27>type count.txt
1025
因此,当断开连接的程序向stdout写入“太多”时,MS的库仍然会被淘汰.取出打印“嗨!”,它“永远”运行.
Python 3
这是Python 3中的“修复”,通过在pythonw.exe下将sys.stdout绑定到None的可疑权宜之计.你可以阅读the history of this mess here.
内容总结
以上是互联网集市为您收集整理的随机“pythonw.exe已停止工作”崩溃全部内容,希望文章能够帮你解决随机“pythonw.exe已停止工作”崩溃所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。