Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 945362c

Browse files
committed
Implement PYTHONNOERRORWINDOW.
1 parent ef0f129 commit 945362c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Modules/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
#endif
1010

1111
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
12+
#include <windows.h>
1213
#ifdef HAVE_FCNTL_H
1314
#include <fcntl.h>
1415
#endif
1516
#endif
1617

18+
#ifdef _MSC_VER
19+
#include <crtdbg.h>
20+
#endif
21+
1722
#if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS)
1823
#define PYTHONHOMEHELP "<prefix>\\lib"
1924
#else
@@ -323,6 +328,25 @@ Py_Main(int argc, char **argv)
323328
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
324329
unbuffered = 1;
325330

331+
#ifdef MS_WINDOWS
332+
if ((p = Py_GETENV("PYTHONNOERRORWINDOW")) && *p != '\0') {
333+
/* Disable all error windows created by the sytem
334+
or the CRT. */
335+
#if defined(_DEBUG) && defined(_MSC_VER)
336+
int types[] = {_CRT_WARN, _CRT_ERROR, _CRT_ASSERT};
337+
int i;
338+
for (i = 0; i < sizeof(types)/sizeof(types[0]); i++) {
339+
_CrtSetReportFile(types[i], _CRTDBG_FILE_STDERR);
340+
_CrtSetReportMode(types[i], _CRTDBG_MODE_FILE);
341+
}
342+
_set_error_mode(_OUT_TO_STDERR);
343+
#endif
344+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
345+
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
346+
}
347+
#endif
348+
349+
326350
if (command == NULL && module == NULL && _PyOS_optind < argc &&
327351
strcmp(argv[_PyOS_optind], "-") != 0)
328352
{

Tools/buildbot/test.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@rem Used by the buildbot "test" step.
22
cd PCbuild
3+
set PYTHONNOERRORWINDOW=1
34
call rt.bat -d -q -uall -rw

0 commit comments

Comments
 (0)