DavidLiu 3 ヶ月 前
コミット
f2466663b5
1 ファイル変更17 行追加6 行削除
  1. 17 6
      src/core/voip/bot.py

+ 17 - 6
src/core/voip/bot.py

@@ -637,12 +637,10 @@ class BotAgent:
             acc = self.accounts.get(user_part)
             if acc:
                 for k, v in acc.calls.items():
-                    try:
-                        self.logger.info('hangup, call_idx=%s, call_active=%s'%(k, v.isActive()))
-                        if v.isActive():
-                            v.hangup(call_op_param)
-                    except:
-                        pass
+                    self.logger.info('hangup, call_idx=%s, call_active=%s'%(k, v.isActive()))
+                    if v.isActive():
+                        self.hangup_with_timeout(v)
+                        # v.hangup(call_op_param)
                 acc.calls.clear()
         except:
             traceback.print_exc()
@@ -650,6 +648,19 @@ class BotAgent:
             # 机器人主动挂机回收分机号
             self.release(user_part)
 
+    def hangup_with_timeout(self, call, timeout=5):
+        def hangup_call():
+            try:
+                call.hangup()
+            except Exception as e:
+                print(f"Failed to hangup call: {e}")
+
+        hangup_thread = threading.Thread(target=hangup_call)
+        hangup_thread.start()
+        hangup_thread.join(timeout)
+        if hangup_thread.is_alive():
+            print("Hangup operation timed out. Proceeding to force stop.")
+
     def register(self, **kwargs):
         self.logger.info('register,come in, pool.size :%d', self.user_part_pool.qsize())
         user_part = self.user_part_pool.get()