Davidliu 1 月之前
父節點
當前提交
c3ee183aca
共有 1 個文件被更改,包括 25 次插入26 次删除
  1. 25 26
      src/core/voip/bot.py

+ 25 - 26
src/core/voip/bot.py

@@ -591,19 +591,22 @@ class BotAgent:
         self._start()
         # threading.Thread(target=self.main_thread_daemon).start()
 
-        self.daemon_job_scheduler = BackgroundScheduler()
-        self.daemon_job_scheduler.add_job(self._main_thread_daemon, 'interval', seconds=1, max_instances=1, name='bot_agent_daemon')
-        self.daemon_job_scheduler.start()
+        # self.daemon_job_scheduler = BackgroundScheduler()
+        # self.daemon_job_scheduler.add_job(self._main_thread_daemon, 'interval', seconds=1, max_instances=1, name='bot_agent_daemon')
+        # self.daemon_job_scheduler.start()
 
     class AsyncJob(pj.PendingJob):
         def __init__(self, agent):
             self.agent = agent
+            self.counter = 0
             super().__init__()
             agent.logger.warn("Job created id: %s", id(self))
 
         def execute(self, is_pending):
             self.agent.logger.warn("Executing job value: %s", is_pending)
-
+            if self.counter >10:
+                self.agent.main_thread_daemon()
+            self.counter += 1
             time.sleep(1)
             self.agent.ep.utilAddPendingJob(self)
 
@@ -666,9 +669,10 @@ class BotAgent:
         self.logger.info("create pjsua already shutdown")
 
 
-    def _main_thread_daemon(self):
+    def main_thread_daemon(self):
         # while not self.daemon_stopping:
-        _lock = self._play_complete_degree_check()
+        # _lock = self._play_complete_degree_check()
+        _lock = True
         if _lock:
             self.logger.error("daviddebugger::play time greater than 60s, will restart")
             self.restart()
@@ -802,29 +806,24 @@ class BotAgent:
         except:
             pass
         self.logger.info("destroy, come in 22222")
-        # self.call_players.clear()
-        # self.accounts.clear()
-        # self.calls.clear()
-        # # Destroy the library
-        # self.ep.libDestroy()
+        self.call_players.clear()
+        self.accounts.clear()
+        self.calls.clear()
+        # Destroy the library
+        self.ep.libDestroy()
         time.sleep(1)
         self.logger.info("destroy, come in 33333")
 
-        if not self.pjsua_thread.is_alive():
-            self.logger.info("destroy, pre thread already stopped")
-            return
-        ident = self.pjsua_thread.ident
-        thread_id = ctypes.pythonapi.PyThreadState_SetAsyncExc
-        res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
-            ctypes.c_long(ident), ctypes.py_object(SystemExit)
-        )
-        self.logger.info("destroy, ident=%s, thread_id=%s, res=%s", ident, thread_id, res)
-        # if res == 0:
-        #     raise ValueError("Invalid thread ID")
-        # elif res > 1:
-        #     # 如果多次调用,需要复位
-        #     ctypes.pythonapi.PyThreadState_SetAsyncExc(ident, 0)
-        #     raise SystemError("PyThreadState_SetAsyncExc failed")
+        # if not self.pjsua_thread.is_alive():
+        #     self.logger.info("destroy, pre thread already stopped")
+        #     return
+        # ident = self.pjsua_thread.ident
+        # thread_id = ctypes.pythonapi.PyThreadState_SetAsyncExc
+        # res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
+        #     ctypes.c_long(ident), ctypes.py_object(SystemExit)
+        # )
+        # self.logger.info("destroy, ident=%s, thread_id=%s, res=%s", ident, thread_id, res)
+
 
 
     def __del__(self):