Skip to content

Instantly share code, notes, and snippets.

@secemp9
Last active May 23, 2024 18:10
Show Gist options
  • Save secemp9/ca83bbec6728e5196fe96b76c3f6fc66 to your computer and use it in GitHub Desktop.
Save secemp9/ca83bbec6728e5196fe96b76c3f6fc66 to your computer and use it in GitHub Desktop.
reload sys module (doesn't actually work it turn out :/)
import sys
import importlib
sys.exit = lambda *args, **kwargs: ...
print(f"sys.exit overridden: {sys.exit}")
importlib.reload(sys)
print(f"sys.exit restored: {sys.exit}")
try:
print("test")
sys.exit(0)
except SystemExit as e:
print(f"SystemExit caught with code: {e.code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment