Python 中的 Microsoft Visual C++ 运行时错误 [英] Microsoft Visual C++ Runtime Error in Python

查看:105
本文介绍了Python 中的 Microsoft Visual C++ 运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在服务器中持续运行的python程序,它将一些数据放入MYSQL数据库并加载一些.它还使用 TCP/IP 连接.问题是,大约 24 小时后,它会出现运行时错误:

I have a python program that runs in a server continuously and it puts some data into MYSQL dataBase and load some. It is also using TCP/IP connection. the problem is that after about 24 hrs it gives a runtime error:

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.

然后我点击 OK python shell 关闭.当我关闭所有 python 文件并检查 Windows 任务管理器时,我看到仍然有一个 pythonw.exe 文件在那里打开!!!

And I hit OK python shell closes. And when I close all python files and check Windows Task Manager I see still there is a pythonw.exe file open there!!!

我正在使用 IDLE 来运行我的应用程序.

I am using IDLE to run my application.

推荐答案

问题

此应用程序已请求运行时终止它不寻常的方式.

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

如果您在运行 Windows 应用程序时收到此错误,很可能是因为在您的 Python 库中的某个地方,甚至可能在您的 Python 运行时中,调用了 abort() 例程.有关详细信息以及调用 abort 的行为,请参阅 有关中止的 MSDN 文档

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. For more information, and the behaviour of calling abort please refer the MSDN documentation on abort

演示

你需要

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

创建一个调用abort()的C DLL,然后使用ctypes调用这个DLL

Create a C DLL which calls abort() and then call this DLL using ctypes

头文件abort_dll.h

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

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

abort_dll.cpp

#include "abort_dll.h"

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

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;
}

现在编译和构建您的 DLL(调试版和发布版).

Now Compile and Build Your DLL (both in Debug and Release Version).

假设我的 DLL 位于以下位置

Assuming my DLLs are present in the following location

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

Debug Version: C:\TEMP\Debug\abort_dll.dll Release Version: C:\TEMP\Release\abort_dll.dll

在你的 IDLE 中执行以下代码

Execute the following code in your IDLE

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

你一定会看到下面的弹窗

You are sure to see the following Popup

与您的情况唯一不同的是,它为您提供了臭名昭著的选项 [Abort|Retry\Ignore].这只是因为我使用了 DLL 的调试版本.相反,如果我使用的是发布版本,我通常会看到

The only difference with your case is, it gives you the infamous option [Abort|Retry\Ignore]. It was only because I had used a Debug version of my DLL. Instead, if I had used a release version, I would typically see

解决方案

在 Windows 中,AFAIK 不能使用信号处理程序处理 SIGABRT.所以,唯一的选择是使用 JIT,我想你已经安装了.然后你会看到以下弹出窗口.

In Windows, AFAIK you cannot handle the SIGABRT with a signal handler. So, the only bet is to use the JIT, that I suppose you had already installed. you would then see the following pop up.

如果您选择调试,则会打开您安装的 JIT 调试器.之后,您可以转储发生故障的堆栈,并确定发生故障的模块.完成后,您可以关联可能调用该模块的 python 模块.

If you would select Debug, that will open your installed JIT debugger. 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 中的 Microsoft Visual C++ 运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆