检查功能是否已执行

时间:2016-08-29 13:10:23

标签: python

首先,对于标题缺乏精确性感到遗憾,我没有受到启发。

我的目标是检查在某个超时后是否调用了类方法。
到目前为止,我的代码如下:

class MyCallCallback(pj.CallCallback):
    def __init__(self, call=None):
        pj.CallCallback.__init__(self, call)

    # Notification when call state has changed
    def on_state(self):
       # Do stuff

        if self.call.info().state == pj.CallState.DISCONNECTED:
            # Do stuff

        elif self.call.info().state == pj.CallState.CONFIRMED:
            # Do stuff

    # Notification when call's media state has changed.
    def on_media_state(self):
        if self.call.info().media_state == pj.MediaState.ACTIVE:
            # Do stuff
        else:
            # Do stuff

并且这样称呼:

def make_call(uri):
    try:
        return acc.make_call(uri, cb=MyCallCallback)
    except pj.Error, e:
        print "Exception: " + str(e)
        return None

当我调用Callback时,我想检查超时后是否触发on_state的事件MyCallBack
我试过这样的东西:

timeout = time.time() + 1
 while time.time() > timeout:
     if [on_state is no triggered]
        sys.exit(-1)

但是找不到合适的方法。

你有什么建议吗?

修改 我不能使用像这样的旗帜系统:

class MyCallCallback(pj.CallCallback):
    on = 0
    timeout = time.time() + 5
    while time.time() < timeout:
        print "Waiting ..."
        pass

    if on != 1:
        print "Fail"
        sys.exit(-1)

    def __init__(self, call=None):
        pj.CallCallback.__init__(self, call)
        self.on = 0

    # Notification when call state has changed
    def on_state(self):
        print "ON_STATE"
        self.on = 1

因为它会同步。

0 个答案:

没有答案