diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-07-21 22:46:35 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-07-21 22:46:35 +0000 |
commit | cc90f28adff7561386a223a634c509d7c4ee97b5 (patch) | |
tree | 9f5c15e6d25fb0751c48012226515742d667dbee | |
parent | cf2b9261e82088e8a0d4d9be9c2133b1ba971550 (diff) |
Added sleep() in python handle events to avoid starvation in the main thread
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2165 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjsip-apps/src/python/pjsua.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/pjsip-apps/src/python/pjsua.py b/pjsip-apps/src/python/pjsua.py index 0eea110f..4d637da6 100644 --- a/pjsip-apps/src/python/pjsua.py +++ b/pjsip-apps/src/python/pjsua.py @@ -152,6 +152,7 @@ import _pjsua import thread import threading import weakref +import time class Error: """Error exception class. @@ -2084,11 +2085,15 @@ class _LibMutex: def __init__(self, lck): self._lck = lck self._lck.acquire() - #print 'lck acquire' + #_Trace(('lock acquired',)) def __del__(self): - self._lck.release() - #print 'lck release' + try: + self._lck.release() + #_Trace(('lock released',)) + except: + #_Trace(('lock release error',)) + pass # PJSUA Library @@ -2115,7 +2120,7 @@ class Lib: def __del__(self): _pjsua.destroy() del self._lock - print 'Lib destroyed' + _Trace(('Lib destroyed',)) def __str__(self): return "Lib" @@ -2167,8 +2172,9 @@ class Lib: self._quit = 1 loop = 0 while self._quit != 2 and loop < 400: - self.handle_events(50) + self.handle_events(5) loop = loop + 1 + time.sleep(0.050) _pjsua.destroy() _lib = None @@ -2180,6 +2186,7 @@ class Lib: thread. """ + lck = self.auto_lock() err = _pjsua.start() self._err_check("start()", self, err) self._has_thread = with_thread @@ -2849,13 +2856,16 @@ def _cb_on_typing(call_id, from_uri, to, contact, is_typing, acc_id): # Worker thread def _worker_thread_main(arg): global _lib + _Trace(('worker thread started..',)) thread_desc = 0; err = _pjsua.thread_register("python worker", thread_desc) _lib._err_check("thread_register()", _lib, err) while _lib and _lib._quit == 0: - _lib.handle_events(50) + _lib.handle_events(1) + time.sleep(0.050) if _lib: _lib._quit = 2 + _Trace(('worker thread exited..',)) def _Trace(args): if True: @@ -2863,3 +2873,4 @@ def _Trace(args): for arg in args: print arg, print " **" + |