File: test_safecall.py

package info (click to toggle)
egenix-mx-base 3.1.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,504 kB
  • ctags: 5,469
  • sloc: ansic: 21,355; python: 14,724; sh: 137; makefile: 102
file content (37 lines) | stat: -rw-r--r-- 872 bytes parent folder | download | duplicates (5)
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.'