[Freeswitch-users] mod_python objects and session cleanup

Novak Joe joes.mailing.lists at gmail.com
Sat Sep 13 23:30:07 EDT 2008


Hi,
  I've been playing around a bit with mod_python and have a question
about using objects and session cleanup.  I put together a trivial
object-based IVR after taking a look at some of the wikipbx examples:
http://fisheye.freeswitch.org:8081/browse/~raw,r=27/WikiPBX/ivr/baseivr.py

  these seem to be based on an older version of mod_python where
PySession and uuid still represented appropriate usage, but with a
couple of minor changes I put something together that seemed
appropriate:

--------------------------------------
# -*- mode: python; coding: utf-8 -*-
from freeswitch import *

class BaseIVR( object ):
    """
        Basic IVR object.
        Defines some common functions and methods.
    """
    def __init__( self, session ):
        self.session = session
        self.session.setInputCallback( self.input_callback )
        self.session.setHangupHook( self.hangup_hook )

    def hangup_hook( self, session, what ):
        """
        Default hangup hook.  Overload as needed.
        """
        consoleLog( "info","The application hung up for %s.\n\n" % what )
        del self.session  #Without this call the session/channel never
gets cleaned-up
        return

    def input_callback( self, session, what, obj ):
        """
        Default input callback for dtmf and other events.  Overload
this as needed.
        """
        if ( what == "dtmf" ):
            consoleLog( "info", what + " " + obj.digit + "\n" )
        else:
            consoleLog( "info", what + " " + obj.serialize() + "\n" )
        return "pause"

    def main( self ):
        """Basic main method."""
        self.session.answer( )
        consoleLog( "info", "Testing my IVR object.\n\n" )
        self.session.hangup( )
        return

def handler( session, args ):
    """Handle the call."""
    basicIVR = BaseIVR( session )
    basicIVR.main( )
--------------------------------------

  The above script works fine, but I noticed that, if I remove the
call to 'del self.session' which I added to the hangup_hook after
reading,
http://jira.freeswitch.org/browse/MODLANG-33

  that the session will not be deleted and, as mentioned in the post
above, calling
freeswitchconsole$ show channels

  will show that there are hanging/open channels.

  Is this because I've created an inappropriate usage scenario, or is
this a bug?

  Is the 'del self.session' an appropriate work-around or is that
likely to cause further problems down the road?


  Cheers,
    Joe



More information about the Freeswitch-users mailing list