Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save baobuiquang/5ef8310ead5a21ba4f69565e2623346b to your computer and use it in GitHub Desktop.

Select an option

Save baobuiquang/5ef8310ead5a21ba4f69565e2623346b to your computer and use it in GitHub Desktop.
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