[ previous ] [ next ] [ threads ]
 To :  =?UTF-8?B?U3RhbmlzxYJhdyBQaXR1Y2hh?= <viraptor@g...>,Yate mailing list <yate@v...>
 From :  Maciek Kaminski <maciejka@t...>
 Subject :  Re: [yate] timeouts in yaypm
 Date :  Mon, 08 Sep 2008 12:53:23 +0200
Stanisław Pitucha:
> Hi,
> I'm trying to setup an onmsg handler with a timeout  in yaypm... It
> doesn't work that well for me.
> 
> I've tried 2 ideas already:
> ---
> dtmf_waiter = yate.onmsg('chan.dtmf', ....)
> reactor.callLater(5, waiter.cancel())
> yield waiter
> 
> This kind of works when I receive a dtmf, but after 5 seconds the call
> explodes anyways and I'm not sure how to catch that.

Hi Stanislaw,

There is no timeout parameter in deferreds created by yaypm. They are 
cancellable though, You just need to catch yaypm.CancelledError or use 
yaypm.utils.XOR. For example modified keyecho example:

          while True:
             timeout, dtmf = yield yaypm.utils.XOR(
                 yate.onmsg("chan.dtmf",
                            lambda m : m["id"] == callid,
                            end),
                 yaypm.utils.sleep(5))

             if timeout:
                 logger.debug("Dtmf timeouted.")
             else:
                 logger.debug("Dtmf %s received." % dtmf["text"])

                 yate.msg("chan.masquerade",
                     {"message" : "chan.attach",
                      "id": targetid,
                      "source": "wave/play/./sounds/digits/pl/%s.gsm" % \
                      dtmf["text"]}).enqueue()

                 dtmf.ret(True)

XOR will fire when any of its parameters fire and will cancel rest.

Adding timeout directly to deffereds are a bit tricky sometimes:
http://twistedmatrix.com/pipermail/twisted-python/2004-April/007536.html

mk