Seems to me you have not implemented a valid tracer function. See the docs in sys (expand below):
Trace functions should have three arguments: frame, event, and arg. frame is the current stack frame. event is a string: 'call', 'line', 'return', 'exception' or 'opcode'. arg depends on the event type.
The trace function is invoked (with event set to 'call') whenever a new local scope is entered; it should return a reference to a local trace function to be used for the new scope, or None if the scope shouldn’t be traced.
The local trace function should return a reference to itself (or to another function for further tracing in that scope), or None to turn off tracing in that scope.
Your trace function needs to look like
def tracefun(frame, event, arg):
# do your tracing here
return tracefun # or return None
Your function accepted no arguments, and returned an integer, not a callable or None.