Patch excepthook and stderr to swallow exception messages by default.

Review Request #253 — Created April 18, 2014 and submitted

wickman
commons
pants-reviews
jsirois, patricklaw
Patch excepthook and stderr to swallow exception messages by default.
mba=science=; cat /tmp/foo.py
import atexit

def foo():
  raise Exception()

atexit.register(foo)

-----

old pex:

mba=science=; pex -- /tmp/foo.py 
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/Users/wickman/Python/CPython-2.6.9/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/tmp/foo.py", line 4, in foo
    raise Exception()
Exception
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/Users/wickman/Python/CPython-2.6.9/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/tmp/foo.py", line 4, in foo
    raise Exception()
Exception


--

new pex:

mba=commons=; dist/pex.pex -- /tmp/foo.py
mba=commons=; PEX_TEARDOWN_VERBOSE=1 dist/pex.pex -- /tmp/foo.py
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/Users/wickman/Python/CPython-2.7.6/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/tmp/foo.py", line 4, in foo
    raise Exception()
Exception
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/Users/wickman/Python/CPython-2.7.6/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/tmp/foo.py", line 4, in foo
    raise Exception()
Exception
PA
  1. Ship It!
  2. 
      
JS
  1. Ship It!
  2. 
      
YA
  1. 
      
  2. src/python/twitter/common/python/pex.py (Diff revision 1)
     
     
    Are the docs[1] accurate? Looks like they're executed in reverse order in which they registered (in theory...)
    
    [1] https://docs.python.org/2/library/atexit.html#atexit.register
    1. this is not the issue -- the issue is that newer versions of twitter.common.python mess with the refcount on sys.modules, so the modules get torn down before atexit handlers get run.
  3. 
      
PA
  1. Speaking of this review--is it on master yet?  I'd love to get this out into the wild at Foursquare ASAP.
    1. It is on master but I just found a bug at r/268 which I will be submitting shortly
    2. ugh, don't use either of these yet.  it swallows all exceptions at the moment.
  2. 
      
WI
Review request changed

Status: Closed (submitted)

Loading...