MCPcopy Index your code
hub / github.com/python/cpython / SuppressCrashReport

Class SuppressCrashReport

Lib/test/support/__init__.py:1886–1979  ·  view source on GitHub ↗

Try to prevent a crash report from popping up. On Windows, don't display the Windows Error Reporting dialog. On UNIX, disable the creation of coredump file.

Source from the content-addressed store, hash-verified

1884
1885
1886class SuppressCrashReport:
1887 """Try to prevent a crash report from popping up.
1888
1889 On Windows, don't display the Windows Error Reporting dialog. On UNIX,
1890 disable the creation of coredump file.
1891 """
1892 old_value = None
1893 old_modes = None
1894
1895 def __enter__(self):
1896 """On Windows, disable Windows Error Reporting dialogs using
1897 SetErrorMode() and CrtSetReportMode().
1898
1899 On UNIX, try to save the previous core file size limit, then set
1900 soft limit to 0.
1901 """
1902 if sys.platform.startswith('win'):
1903 # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
1904 try:
1905 import msvcrt
1906 except ImportError:
1907 return
1908
1909 self.old_value = msvcrt.GetErrorMode()
1910
1911 msvcrt.SetErrorMode(self.old_value | msvcrt.SEM_NOGPFAULTERRORBOX)
1912
1913 # bpo-23314: Suppress assert dialogs in debug builds.
1914 # CrtSetReportMode() is only available in debug build.
1915 if hasattr(msvcrt, 'CrtSetReportMode'):
1916 self.old_modes = {}
1917 for report_type in [msvcrt.CRT_WARN,
1918 msvcrt.CRT_ERROR,
1919 msvcrt.CRT_ASSERT]:
1920 old_mode = msvcrt.CrtSetReportMode(report_type,
1921 msvcrt.CRTDBG_MODE_FILE)
1922 old_file = msvcrt.CrtSetReportFile(report_type,
1923 msvcrt.CRTDBG_FILE_STDERR)
1924 self.old_modes[report_type] = old_mode, old_file
1925
1926 else:
1927 try:
1928 import resource
1929 self.resource = resource
1930 except ImportError:
1931 self.resource = None
1932 if self.resource is not None:
1933 try:
1934 self.old_value = self.resource.getrlimit(self.resource.RLIMIT_CORE)
1935 self.resource.setrlimit(self.resource.RLIMIT_CORE,
1936 (0, self.old_value[1]))
1937 except (ValueError, OSError):
1938 pass
1939
1940 if sys.platform == 'darwin':
1941 import subprocess
1942 # Check if the 'Crash Reporter' on OSX was configured
1943 # in 'Developer' mode and warn that it will get triggered

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…