Created
May 19, 2025 01:21
-
-
Save baobuiquang/5ef8310ead5a21ba4f69565e2623346b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import logging | |
| logging.basicConfig(filename='_log_crash.log', level=logging.ERROR, format='--------------------------------------------------\n%(asctime)s\n%(levelname)s: %(message)s\n') | |
| def log_crashes(exc_type, exc_value, exc_traceback): | |
| logging.error("CRASHED - Unhandled exception occurred", exc_info=(exc_type, exc_value, exc_traceback)) | |
| sys.excepthook = log_crashes | |
| def simulate_memory_error(): | |
| massive_list = [bytearray(1024 * 1024 * 1000) for _ in range(1000)] | |
| return massive_list | |
| def main(): | |
| print("Attempting to simulate memory error...") | |
| result = simulate_memory_error() | |
| print(f"Allocated list with {len(result)} items") # Won't reach here | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment