Last active
August 29, 2015 14:15
-
-
Save auscompgeek/3eea0698c4be5e0b69f2 to your computer and use it in GitHub Desktop.
@flowblok's implementation of https://twitter.com/auscompgeek/status/551883315486019584 - improved
This file contains 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
# An implementation of the james_curran variable #drjcfacts | |
# https://twitter.com/auscompgeek/status/551883315486019584 | |
# | |
# Originally by @flowblok | |
# Improved by @auscompgeek | |
# | |
# Original version by @flowblok is available in r1 of this gist: | |
# https://gist.github.com/auscompgeek/3eea0698c4be5e0b69f2/e56d405d67309c6b121e0a6beb1f97a523281300 | |
# | |
# TODO: fix for custom excepthooks such as the one in IPython | |
james_curran = True | |
def trace(f, t, v, p=[james_curran]): | |
try: | |
import sys | |
import traceback | |
except Exception: | |
return | |
def r(c, m): | |
g['james_curran'] = p[0] | |
sys.stderr.write('Traceback (most recent call last):\n') | |
traceback.print_stack(f, limit=3) | |
sys.excepthook(c, c(m), None) | |
g = globals() | |
if 'james_curran' not in g: | |
r(RuntimeError, 'james_curran cannot be deleted') | |
return | |
j = g['james_curran'] | |
if j: | |
p[0] = j | |
else: | |
r(ValueError, 'james_curran must be truthy') | |
__import__('sys').setprofile(trace) | |
del trace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment