【发布时间】: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