File: TestTerminationCrash.py

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (33 lines) | stat: -rwxr-xr-x 1,413 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/env python

import vtk

class TerminationCrashTestCase:

    """This test case should produce a crash on termination if we aren't
    careful in DECREFing a Python callback via vtkPythonCommand.

    The problem occurs only when you have an uncollectable reference
    cycle with an observer callback.    This should cause a crash upon
    termination (trying to delete python object after interpreter
    shutdown), or an assertion error if the observed event is
    'DeleteEvent' or 'AnyEvent' (trying to invoke python method after
    interpreter shutdown). The test case basically consists of a python
    class which contains a vtk object which is being observed by that
    same class. There is no error if the event handler is a member of a
    different class, even if the instance of that class is contained by
    the same python object which contains the vtk object. There is also
    no error if a vtk object is subclassed in python and that subclass
    has an event handler for itself (self.AddObserver(Event,
    self.Handler)). Finally, the problem disappears if the container
    class has a cyclic reference to itself (self.CyclicReference =
    self).  """

    def __init__(self) :
        self.Object = vtk.vtkObject()
        self.Object.AddObserver('StartEvent', self.Handler)
    def Handler(self, obj, evt) :
        print('event received')

test = TerminationCrashTestCase()