[英]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 你需要
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 需要的工具
Steps to Debug 调试步骤
Add the following filters (Cntrl + F) 添加以下过滤器(Cntrl + F)
Search the LOG for a call to WerFault.exe 在LOG中搜索对WerFault.exe的调用
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。
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.