简体   繁体   English

Python中的Microsoft Visual C ++运行时错误

[英]Microsoft Visual C++ Runtime Error in Python

I have a python program that runs in a server continuously and it puts some data into MYSQL dataBase and load some. 我有一个连续在服务器上运行的python程序,它将一些数据放入MYSQL数据库并加载一些。 It is also using TCP/IP connection. 它还使用TCP / IP连接。 the problem is that after about 24 hrs it gives a runtime error: 问题是大约24小时后它会产生运行时错误:

Microsoft Visual C++ Runtime Library!

Runtime Error!

Program: C:\python27\pythonw.exe

This application has requested the Runtime to terminate it in an unusual way.

And I hit OK python shell closes. 然后我打开OK python shell关闭。 And when I close all python files and check Windows Task Manager I see still there is a pythonw.exe file open there!!! 当我关闭所有python文件并检查Windows任务管理器时,我看到仍然有一个pythonw.exe文件打开!!!

I am using IDLE to run my application. 我正在使用IDLE来运行我的应用程序。

Problem 问题

This application has requested the Runtime to terminate it in an unusual way. 此应用程序已请求Runtime以不寻常的方式终止它。

If you ever receive this error while running a windows application, it is most possibly because somewhere in your python library, and even possible from your python runtime, abort() routine was called. 如果你在运行Windows应用程序时遇到这个错误,很可能是因为python库中的某个地方,甚至可能是你的python运行时,调用了abort()例程。 For more information, and the behaviour of calling abort please refer the MSDN documentation on abort 有关更多信息以及调用abort的行为,请参阅有关中止MSDN文档

Demo 演示

You would need 你需要

  1. Visual Studio 2008 (Express Edition) Visual Studio 2008(Express Edition)
  2. Setting the Microsoft Symbol Server correctly in _SYM_PATH 在_SYM_PATH中正确设置Microsoft Symbol Server
  3. Python 2.7 Python 2.7
  4. Install WinDBG , and set it up as JIT 安装WinDBG ,并将其设置为JIT

Create a C DLL which calls abort() and then call this DLL using ctypes 创建一个调用abort()的C DLL,然后使用ctypes调用此DLL

Header File abort_dll.h 头文件abort_dll.h

#include<cstdlib>
#include <windows.h>

extern "C"  __declspec(dllexport) void call_abort(void);

Source abort_dll.cpp 来源abort_dll.cpp

#include "abort_dll.h"

__declspec(dllexport) void call_abort(void)
{
    abort();
}

Source dllmain.cpp 来源dllmain.cpp

#include "abort_dll.h"
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Now Compile and Build Your DLL (both in Debug and Release Version). 现在编译和构建你的DLL(在Debug和Release Version中)。

Assuming my DLLs are present in the following location 假设我的DLL存在于以下位置

Debug Version: C:\\TEMP\\Debug\\abort_dll.dll Release Version: C:\\TEMP\\Release\\abort_dll.dll 调试版本:C:\\ TEMP \\ Debug \\ abort_dll.dll发行版:C:\\ TEMP \\ Release \\ abort_dll.dll

Execute the following code in your IDLE 在IDLE中执行以下代码

from ctypes import *
hDLL = WinDLL(r"C:\TEMP\Debug\abort_dll.dll")
hDLL.call_abort()

You are sure to see the following Popup 您一定会看到以下弹出窗口

在此输入图像描述

The only difference with your case is, it gives you the infamous option [Abort|Retry\\Ignore]. 与你的情况唯一不同的是,它为你提供了臭名昭着的选项[Abort | Retry \\ Ignore]。 It was only because I had used a Debug version of my DLL. 这只是因为我使用了我的DLL的Debug版本。 Instead, if I had used a release version, I would typically see 相反,如果我使用了发布版本,我通常会看到

在此输入图像描述

Solution

In Windows, AFAIK you cannot handle the SIGABRT with a signal handler. 在Windows,AFAIK中,您无法使用信号处理程序处理SIGABRT So, the only bet is to use the JIT, that I suppose you had already installed. 所以,唯一的赌注是使用JIT,我想你已经安装了。 you would then see the following pop up. 然后你会看到以下弹出窗口。

在此输入图像描述

If you would select Debug, that will open your installed JIT debugger. 如果选择Debug,将打开已安装的JIT调试器。 After which, you can dump the failing stack, and determine the failing module. 之后,您可以转储发生故障的堆栈,并确定发生故障的模块。 Once done, you can then correlate what could be the python module that might have called the module. 完成后,您可以关联可能已调用模块的python模块。

In my former answer, I tried to introduce about the reason for the reported behavior and how one can debug and determine the root cause. 在我之前的回答中,我试图介绍报告行为的原因以及如何调试和确定根本原因。 Unfortunately, this requires an extensive debugging knowledge and time to isolate the problem. 不幸的是,这需要大量的调试知识和时间来隔离问题。

Alternatively, Process Monitor can some handy to give a high level understanding of the problem, which as a User would post possibly need. 或者, Process Monitor可以方便地对问题进行高级别的理解,这可能是用户可能需要的。

Tools Required 需要的工具

  1. Process Monitor 进程监视器

Steps to Debug 调试步骤

  1. Run Process Monitor 运行Process Monitor
  2. Add the following filters (Cntrl + F) 添加以下过滤器(Cntrl + F)

    1. Process Name - begins with - python 进程名称 - 以--python开头
    2. Operation - begins with - CreateFile 操作 - 以 - CreateFile开头

    在此输入图像描述

  3. Now keep running procmon, until your application Crashes 现在继续运行procmon,直到你的应用程序崩溃
  4. Stop Capture (Cntrl + E) 停止捕捉(Cntrl + E)
  5. Search the LOG for a call to WerFault.exe 在LOG中搜索对WerFault.exe的调用

    在此输入图像描述

  6. Gradually scroll up to see the last called Non Windows DLL which may be related to Python. 逐渐向上滚动以查看可能与Python相关的最后一个名为Non Windows DLL。 In the above case, its abort_dll.dll. 在上面的例子中,它的abort_dll.dll。

  7. Now use your Python library knowledge, or ask across (including SO), to determine, what could be the failing. 现在使用您的Python库知识,或询问(包括SO),以确定可能是失败的。 Even, from the log, you can identify, which Python Module called this DLL by scrolling further up. 甚至,从日志中,您可以通过进一步向上滚动来识别哪个Python模块称为此DLL。

I was able to fix the same issue by eliminating the initiated, yet not displayed plots. 通过消除已启动但尚未显示的图,我能够解决同样的问题。 It was: 它是:

plt.plot(dI_new[ref:idx_stop], w_new[ref:idx_stop], 'ro') #x,y
plt.xlabel('Strain')
plt.ylabel('Stress, kPa')
##plt.axis([0, 6, 0, 20])
##plt.show()

I fix it for: 我解决它:

##plt.plot(dI_new[ref:idx_stop], w_new[ref:idx_stop], 'ro') #x,y
##plt.xlabel('Strain')
##plt.ylabel('Stress, kPa')
##plt.axis([0, 6, 0, 20])
##plt.show()

The error doesn't show up anymore. 该错误不再显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:需要 Microsoft Visual C++ 14.0。 使用“Microsoft Visual C++ Build Tools”获取 Python 模块安装 - Error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools” for Python module installing 适用于 Python 2.7 的 Microsoft Visual C++ 编译器 - Microsoft Visual C++ Compiler for Python 2.7 是否有适用于 Python 3.7.1 的 Microsoft Visual C++ 编译器? - Is there a Microsoft Visual C++ Compiler for Python 3.7.1? 用于Python 3.4的Microsoft Visual C ++编译器 - Microsoft Visual C++ Compiler for Python 3.4 用于 python 的微软 Visual C++ 编译器 - microsoft visual c++ compiler for python 适用于Python 2.7的Visual Microsoft Visual C ++编译器与MinGW - Visual Microsoft Visual C++ Compiler for Python 2.7 vs MinGW 错误:需要Microsoft Visual C ++ 14.0。 使用“ Microsoft Visual C ++ Build Tools”获得它 - error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools” scrapy 需要Microsoft Visual C ++ 14.0。 下载python软件包时出现错误 - Microsoft Visual C++ 14.0 is required. error when downloading a python package Python 错误:需要 Microsoft Visual C++ 14.0,尽管它已经安装 - Python error: Microsoft Visual C++ 14.0 is required, although it has been already installed 安装 python package 和 Z62AD1C2A46C3BBF8958 时,如何使用 Microsoft Visual C++ 构建工具修复致命错误 1104 - How to fix fatal error 1104 with Microsoft Visual C++ Build Tools when installing a python package with pip?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM