Python: Call class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again,

I played a bit with the library: added some dummy (printf) statements
into pjsua_call_get_user_data (just right before the PJ_ASSERT macro;
pjsua_call.c), enabled tracing in pjsua.py (pjsua.enable_trace = True)
and added one line to __del__ method of Call class (also in pjsua.py):

def __del__(self):
    _Trace((self, 'destroying'))
    if self._id != -1:
        _pjsua.call_set_user_data(self._id, 0)
    _Trace((self, 'destroyed'))

The result:

**  {Transport udp 0.0.0.0:5080 [published as 127.0.0.1:5080]} created
**
**  {Transport udp 0.0.0.0:5080 [published as 127.0.0.1:5080]} destroyed
**
**  {Account <sip:ble at ble>} created  **
**  worker thread started..  **
**  {Call object} created  **
call_id: 0
pjsua_var.ua_cfg.max_calls: 4
#
# 10x times the same
#
call_id: 0
pjsua_var.ua_cfg.max_calls: 4
**  worker thread exited..  **
call_id: 0
pjsua_var.ua_cfg.max_calls: 4
disco
call_id: 0
pjsua_var.ua_cfg.max_calls: 4
**  Lib destroyed  **
**  {Call sip:bla at bla} destroying  **
call_id: 0
pjsua_var.ua_cfg.max_calls: 0

... and the same assert-abort message
>From looking@the C code I would guess that the first few prints of
call_id & max_calls are from Call-instance initialization. The following
are called in _pjsua.c:py_pjsua_call_set_user_data() (which then calls
pjsua_call_get_user_data) on status changes.
When the library gets destroyed, Python (or interpreter) decrements by
one the reference count for the instance of class Call and tries to call
__del__ which ends in assertion abort.
By writing this (at first desperate) mail I found a probably forgotten
detail (IMHO should be explicitly mentioned in the tutorial example:
call.py, I could change it, if somebody puts it on trac wiki). Before
destroying the lib, the developer should explicitly make sure to get rid
of the Call instances ("del call" in my code):

<snip />
     acc = lib.create_account(pj.AccountConfig('server.com', 'user', 'secret'))
     acc_cb = AccountCallback(acc)
     acc.set_callback(acc_cb)
     acc_cb.wait()
     call = None
 
     if len(sys.argv) == 2:
         call = acc.make_call(sys.argv[1], CallCallback())
 
     raw_input('press ENTER to quit')
     del call       # !!! explicitly invoking __del__()
     lib.destroy()
<snip />

Which raises a question: does the same problem occur for Account? I
didn't get an error (yet :P).

Sorry for the long mail (I probably stated the obvious) :)
Karol




[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux