Threading issue in Python example

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

 



Greetings,

 

I have read about the threading issues with using Python but I don’t quite understand
what I can do to properly synchronize the main in a simple script with, for example, the registration
state of a SIP account.  In trying to understand how to do it I have found that even the
simple Python demo at https://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html
will cause a seg fault due to the time.sleep() call.  Note that for the script to work you must
add import pjsua as pj and import time to it.  But that’s mainly all I did and of course I changed
the SIP registrar URI to my SIP proxy.  Oh, and I updated the print to be compatible with
python3.  Maybe running with python3 is an issue?  Anyway, if I take out the time.sleep

call then no seg fault.  But with it I get a seg fault.

I discovered this after frustrating hours trying to post a semaphore from the onRegState
callback and wait on the semaphore in the main thread.  I thought it was something to
do with the use of the semaphore but then removed that and tried just running with
the thread.sleep and to my surprise that was enough to cause the seg fault. 
Just making the one-line change to my script to comment out the call to thread.sleep
as below makes it register successfully with my proxy.

    …

    acc = Account();

    acc.create(acfg);

  # Here we don't have anything else to do..

  time.sleep(10);

 

The preceding works causes a seg fault

But the following does not and all works wonderfully:

 

    acc = Account();

    acc.create(acfg);

  # Here we don't have anything else to do..

  # time.sleep(10);

 

 

Thanks,

Mike

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[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