Could you wrap your function i a decorator that maintains a counter that gets incremented everytime the function is called?

On Tue, Sep 7, 2010 at 5:14 PM, Cliff Hill <xlorep@darkhelm.org> wrote:
I'm looking for a clever way to identify recursive calls (so I can count them accurately in my sorting app I've been working on).  Right now, I am basically doing a stack trace in Java, and identifying all of the python function calls with in it, and then figuring out whenever there is a recursive call by seeing if the same function appears multiple times within the stack:

    String getPyFunc() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        List<String> funcNames = new ArrayList<String>();
        for (int i = 0; i < stackTrace.length; i++) {
            if (stackTrace[i].getMethodName().equals("call_function")) {
                String funcName = stackTrace[i - 1].getMethodName();
                funcName = funcName.substring(0, funcName.indexOf('$'));

                funcNames.add(funcName);
            }
        }

        if (!getFuncStack().isEmpty()
                && getFuncStack().size() != funcNames.size()
                && getFuncStack().get(0).equals(funcNames.get(0))) {
            log.finest("*** Recursion Identified ***");
            incrRecurses();
        }

        setFuncStack(funcNames);

        return getFuncStack().get(0);
    }

But what I am wandering is if there is a better way, where upon having a function called, the system can properly identify that it is a recursive call at execution. Does anyone have any suggestions?




--
"I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm
Website: http://darkhelm.org

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users




--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.