From: Mike C. F. <mcf...@vr...> - 2007-11-27 18:07:36
|
Josef Novak wrote: > In response to my own thread, I've put together a new script which > does almost everything I need, except for properly handling multiple > calls. I am almost certainly missing the boat with twisted/starpy > here, because I cannot seem for the life of me to write a non-trivial > location which will allow my box to process more than one incoming > call at a time. As soon as I stick a time.sleep( 15 ) command in the > script, the next call cant get through until the sleep finishes which > is highly undesirable. > > Any suggestions for turning the attached example into something which > will properly process multiple simultaneous calls without removing the > sleep command would be deeply appreciated. > Joe, you *cannot* *ever* use sleep in a Twisted mainloop. Twisted is an asynchronous networking library. If you sleep the entire process will stop. Use the reactor.callLater( duration, func, *args, **named ) function to schedule something to run at a later time. In generally you cannot "block" in the mainloop at all, if you do everything goes to heck. If you *really* need something blocking to occur you need to use the Twisted threading API. You can schedule post-call events to occur just by doing a callLater operation as well, btw. Sorry, haven't time to rebuild my asterisk server and test the code, but if that's the approach you're taking I can tell you it just won't work and you need to use "the Twisted way" for it. Good luck, Mike > 2007/11/25, Josef Novak <jos...@gm...>: > >> Hi, >> This is in response to a rather older thread, regarding handling >> multiple calls. The script listed by the original poster works fine >> for me, I am able to handle multiple calls with the same fastagi >> instance. However, in the response to the poster's question: >> >>> 1. Is this the StarPythonic way to do this? Should I instead be >>> >> subclassing FastAgiFactory? >> >> Mike Fletcher wrote: >> >>> The normal pattern in StarPy would be to create a core handler that >>> >> dispatches per-connection objects to handle a given call. See the >> examples/calldurationcallback.py module for an example... >> >> However, I was unable to get the calldurationcallback.py example to >> handle multiple calls. If I try to call in again while an earlier >> call is still going on, the second call is forced to wait on the line >> until the second one ends. This is obviously not very useful >> behavior, so I wonder what it is that I am doing wrong. Is there a >> particular way I should be starting up calldurationcallback.py, with >> twistd and a specific set of arguments for example? Thus far the only >> script I've been able to achieve this essential functionality with is >> the below original posting for this thread, any specific advice in the >> right direction regarding how to do this the starpy way, or even just >> how to get the calldurationcallback.py to a point where it can field >> multiple calls would be a great help. >> >> -joe >> >> >>> I am just getting going with StarPy and AGI (aka newbie) but I am dCap >>> certified so I have a good understanding of asterisk in general. In my first >>> attempt to understand StarPy I ran into an issue with handling more than one >>> call into the same fastagi instance. It turns out this was pretty >>> >> easy to figure >> >>> out, but I thought it would be good to share. I started with the following >>> fastagi script: ... >>> >> # START CODE >> #!/usr/bin/env python >> >> from twisted.internet import reactor, defer >> from starpy import fastagi, error >> >> import logging >> log = logging.getLogger( 'testagi' ) >> log.setLevel( logging.DEBUG ) >> >> class TestAgi( object ): >> >> def __call__( self , agi ): >> >> self.agi = agi >> >> log.debug("self.agi is now <%s>" % self.agi.variables['agi_uniqueid']) >> >> return self.agi.wait( 15 ).addCallback( self.waited1 ) >> >> def waited1( self, results ): >> >> log.debug("self.agi in waited1 now <%s>" % \ >> self.agi.variables['agi_uniqueid']) >> >> return self.agi.hangup( ) >> >> if __name__ == "__main__": >> logging.basicConfig() >> fastagi.log.setLevel( logging.DEBUG ) >> f = fastagi.FastAGIFactory(TestAgi( )) >> reactor.listenTCP(4573, f, 50, '127.0.0.1') >> reactor.run() >> >> # END CODE >> >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2005. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Starpy-users mailing list >> Sta...@li... >> https://lists.sourceforge.net/lists/listinfo/starpy-users -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |