用于在等待10秒时显示星号的Python脚本

问题描述 投票:0回答:2

我正在尝试使用python AGI脚本在星号中“保持”呼叫,该功能将检查该人是否可用,当他是星号时将拨打该人,如果他不是该脚本应该等待10秒再检查再次可用,并在有人可用时拨打。但是我遇到了一个小问题,当一个人不在时,使用time.sleep(10)函数挂断电话,我希望这是因为脚本运行的线程将睡眠并且星号认为脚本已完成运行并挂断电话。删除time.sleep()给了我我想要的没有时间间隔。

agi = AGI()
agi.verbose("python agi started")
place_call_on_hold("SIP/6001")

def place_call_on_hold(s):
  agi.verbose("entered place_call_on_hold function")
  while True:
    status = agi.get_variable('DEVICE_STATE(%(redirect)s)'%{'redirect':s})
    agi.verbose(status)
    if status == 'NOT_INUSE':
      agi.verbose("Info: place_call_on_hold: calling the number")
      agi.appexec("Dial",s)
    else:
      agi.verbose("Info: place_call_on_hold: sleeping for 10 sec")
      time.sleep(10)

有没有办法在不使用sleep()函数的情况下等待10秒,或者如何在time.sleep唤醒之前确保调用不会结束?

python asterisk agi
2个回答
0
投票

为什么不在条件之前和条件之后尝试时差

import time

start = time.time()
end = time.time()

while (end-start) < 10:
    end = time.time()
print(start, end, end-start)

0
投票

我通过调用Asterisk Wait(10)函数而不是time.sleep(10)来解决我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.