msvcrt python linux,Python msvcrt.CrtSetReportMode方法代码示例

# 需要导入模块: import msvcrt [as 别名]

# 或者: from msvcrt import CrtSetReportMode [as 别名]

def __enter__(self):

"""On Windows, disable Windows Error Reporting dialogs using

SetErrorMode.

On UNIX, try to save the previous core file size limit, then set

soft limit to 0.

"""

if sys.platform.startswith('win'):

# see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx

# GetErrorMode is not available on Windows XP and Windows Server 2003,

# but SetErrorMode returns the previous value, so we can use that

import ctypes

self._k32 = ctypes.windll.kernel32

SEM_NOGPFAULTERRORBOX = 0x02

self.old_value = self._k32.SetErrorMode(SEM_NOGPFAULTERRORBOX)

self._k32.SetErrorMode(self.old_value | SEM_NOGPFAULTERRORBOX)

# Suppress assert dialogs in debug builds

# (see http://bugs.python.org/issue23314)

try:

import msvcrt

msvcrt.CrtSetReportMode

except (AttributeError, ImportError):

# no msvcrt or a release build

pass

else:

self.old_modes = {}

for report_type in [msvcrt.CRT_WARN,

msvcrt.CRT_ERROR,

msvcrt.CRT_ASSERT]:

old_mode = msvcrt.CrtSetReportMode(report_type,

msvcrt.CRTDBG_MODE_FILE)

old_file = msvcrt.CrtSetReportFile(report_type,

msvcrt.CRTDBG_FILE_STDERR)

self.old_modes[report_type] = old_mode, old_file

else:

if resource is not None:

try:

self.old_value = resource.getrlimit(resource.RLIMIT_CORE)

resource.setrlimit(resource.RLIMIT_CORE,

(0, self.old_value[1]))

except (ValueError, OSError):

pass

if sys.platform == 'darwin':

# Check if the 'Crash Reporter' on OSX was configured

# in 'Developer' mode and warn that it will get triggered

# when it is.

#

# This assumes that this context manager is used in tests

# that might trigger the next manager.

value = subprocess.Popen(['/usr/bin/defaults', 'read',

'com.apple.CrashReporter', 'DialogType'],

stdout=subprocess.PIPE).communicate()[0]

if value.strip() == b'developer':

print("this test triggers the Crash Reporter, "

"that is intentional", end='', flush=True)

return self

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值