【问题标题】:Python script stops working with BEX errorPython 脚本停止使用 BEX 错误
【发布时间】:2017-11-01 08:03:46
【问题描述】:

我有一个在 Windows 上运行的 Python 脚本,它基本上是具有多个 SQL 数据库连接的 RESTful 接口客户端。它必须在一段时间后重新启动(例如,15 分钟)。为此,我使用函数os.execl() 将代码包装在循环中。我使用以下格式从 PowerShell 运行脚本:

PS C:\test> python.exe .\script.pyc

脚本本身(不透露实现细节):

import base64
import datetime
import glob
import logging
import os
import socket
import sys
import threading
import time
import pyodbc
import binascii
import configparser
import codecs
import requests
from collections import namedtuple
from binascii import unhexlify, b2a_base64

FORMAT = '%(asctime)-15s %(levelname)-10s %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)
log = logging.getLogger()

# some class declarations here

if __name__ == '__main__':

    # Initializing counter for time
    timeLast = time.time()

    while 1:
        timeCurrent = time.time()
        if ((timeCurrent - timeLast) > resetTime):
            timeLast = timeCurrent
            os.execl(sys.executable, sys.executable, * sys.argv)

        try:        
            # Fetching data from DB
            # Processing data

        except Exception as e:
            log.error(repr(e))
            time.sleep(1)

# Wait for user input before exiting
sys.stdin.read()

但是,在运行几天后,脚本停止工作并出现以下缓冲区溢出异常 (BEX):

故障应用程序 python.exe,版本 3.6.3150.1013,时间戳 0x59d3c90d,故障模块 ucrtbase.dll,版本 10.0.10586.1171, 时间戳 0x59ae5046,异常代码 0xc0000417,故障偏移 0x000834c4,进程id 0xecc,应用程序启动时间 0x01d351c6613b826e.

我还注意到 PowerShell 控制台窗口不会刷新窗口内容,除非我将其窗口置于焦点并按下箭头。也许是一些不同的问题。

环境:

  • Windows Server Standard SP2(32 位)
  • PowerShell 2.0
  • Python 3.6.3

【问题讨论】:

    标签: python windows powershell


    【解决方案1】:

    似乎问题与脚本在 PowerShell 中运行这一事实有关。在 Python Shell 中运行脚本时未观察到。

    【讨论】:

    • 嗨。我遇到了和你一样的问题。请问您是如何解决这个错误的?
    • 嗨,@jonilyn2730,我实际上并没有修复它。我只是不再将 PowerShell 用于长时间运行的 Python 脚本。 Python shell 对我来说已经足够好了。
    猜你喜欢
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多