/usr/share/pyshared/mx/Tools/mxTools/test_safecall.py is in python-egenix-mxtools 3.2.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """ Test safecall() mxTools API.
"""
import mxTools, os, signal
def simulate_segfault():
os.kill(os.getpid(), signal.SIGSEGV)
# Make sure Python catches the signal
for i in range(10000):
pass
def real_segfault(errtype=0):
mxTools.segfault(errtype)
print 'Simulating programming errors ...'
for i in range(5):
print ' Try %i' % i
try:
mxTools.safecall(simulate_segfault)
except RuntimeError, reason:
print ' RuntimeError: %s' % reason
else:
print ' No RuntimeError ?!'
print
print 'Real world programming errors ...'
for errtype in range(5):
print ' Error type %i' % errtype
try:
mxTools.safecall(real_segfault, (errtype,))
except RuntimeError, reason:
print ' RuntimeError: %s' % reason
else:
print ' No RuntimeError ?!'
print
print 'Works.'
|