Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auscompgeek/3eea0698c4be5e0b69f2 to your computer and use it in GitHub Desktop.
Save auscompgeek/3eea0698c4be5e0b69f2 to your computer and use it in GitHub Desktop.
# 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