def run(self): self.notification_center.post_notification('SIPEngineWillStart', sender=self) init_options = Engine.default_start_options.copy() init_options.update(self._options) try: self._ua = PJSIPUA(self._handle_event, **init_options) except Exception: log.exception('Exception occurred while starting the Engine') exc_type, exc_val, exc_tb = sys.exc_info() exc_tb = "".join( traceback.format_exception(exc_type, exc_val, exc_tb)) self.notification_center.post_notification('SIPEngineGotException', sender=self, data=NotificationData( type=exc_type, value=exc_val, traceback=exc_tb)) self.notification_center.post_notification('SIPEngineDidFail', sender=self) return else: self.notification_center.post_notification('SIPEngineDidStart', sender=self) failed = False while not self._thread_stopping: try: failed = self._ua.poll() except: log.exception('Exception occurred while running the Engine') exc_type, exc_val, exc_tb = sys.exc_info() self.notification_center.post_notification( 'SIPEngineGotException', sender=self, data=NotificationData(type=exc_type, value=exc_val, traceback="".join( traceback.format_exception( exc_type, exc_val, exc_tb)))) failed = True if failed: self.notification_center.post_notification('SIPEngineDidFail', sender=self) break if not failed: self.notification_center.post_notification('SIPEngineWillEnd', sender=self) self._ua.dealloc() del self._ua self.notification_center.post_notification('SIPEngineDidEnd', sender=self)
def start(self, **kwargs): if self._thread_started: raise SIPCoreError("Worker thread was already started once") init_options = Engine.default_start_options.copy() init_options.update(kwargs) self._post_notification("SIPEngineWillStart") with self._lock: try: self._thread_started = True self._ua = PJSIPUA(self._handle_event, ip_address=None, **init_options) Thread.start(self) except: self._thread_started = False if hasattr(self, "_ua"): self._ua.dealloc() del self._ua self._post_notification("SIPEngineDidFail") raise else: self._post_notification("SIPEngineDidStart")
def run(self): self.notification_center.post_notification('SIPEngineWillStart', sender=self) init_options = Engine.default_start_options.copy() init_options.update(self._options) for k in list(init_options['events'].keys()): if isinstance(k, str): init_options['events'][k.encode()] = init_options['events'][k] del (init_options['events'][k]) for k in list(init_options['events'].keys()): init_options['events'][k] = list( v.encode() if isinstance(v, str) else v for v in init_options['events'][k]) try: self._ua = PJSIPUA(self._handle_event, **init_options) except Exception: log.exception('Exception occurred while starting the Engine') exc_type, exc_val, exc_tb = sys.exc_info() exc_tb = "".join( traceback.format_exception(exc_type, exc_val, exc_tb)) self.notification_center.post_notification('SIPEngineGotException', sender=self, data=NotificationData( type=exc_type, value=exc_val, traceback=exc_tb)) self.notification_center.post_notification('SIPEngineDidFail', sender=self) return else: self.notification_center.post_notification('SIPEngineDidStart', sender=self) failed = False while not self._thread_stopping: try: failed = self._ua.poll() except Exception as e: log.exception('Exception occurred while running the Engine') traceback.print_exc() exc_type, exc_val, exc_tb = sys.exc_info() self.notification_center.post_notification( 'SIPEngineGotException', sender=self, data=NotificationData(type=exc_type, value=exc_val, traceback="".join( traceback.format_exception( exc_type, exc_val, exc_tb)))) failed = True if failed: self.notification_center.post_notification('SIPEngineDidFail', sender=self) break if not failed: self.notification_center.post_notification('SIPEngineWillEnd', sender=self) self._ua.dealloc() del self._ua self.notification_center.post_notification('SIPEngineDidEnd', sender=self)