Thanks Stefan,
Yes I found it late last night. My problem was that I was trying from within
a python module. Once I put my code into the ivr/py directory, and loaded
similarly to log.py - it all works.
Seems I missed the part about createThread only working from the onLoad
ivrFactory :D
Thanks for your detailed response.
Cheers
Jason
On Wed, Jul 9, 2008 at 12:18 AM, Stefan Sayer <[EMAIL PROTECTED]>
wrote:
>
>
> o Jason Penton [07/08/08 17:23]:
>
>> Hey Stefan
>>
>> > [...]
>
>>
>> I have very similar code to this but the run method never seems to be
>> executed not even the debug statement. Output looks as follows:
>>
>>
>> (12633) DEBUG: run (Ivr.cpp:193): PythonScriptThread - calling python
>> function.
>> (12633) DEBUG: run (Ivr.cpp:195): PythonScriptThread - thread finished..
>>
>> i.e. i am assuming my debug statement should have been printed between the
>> above 2 calls.
>>
>> I had a quick look at Ivr.cpp and it seems that the createThread function
>> accepts a tuple. Is it possible that there has been a code change since you
>> last used your thread code. Im stumped at the moment?
>>
> I haven't tried it with trunk, but i still have this code in there:
>
> bool IvrDialog::callPyEventHandler(char* name, char* fmt, ...)
> {
> bool ret=false;
> va_list va;
>
> PYLOCK;
>
> va_start(va, fmt);
> PyObject* o = PyObject_VaCallMethod(py_dlg,name,fmt,va);
> va_end(va);
>
> if(!o) {
>
> if(PyErr_ExceptionMatches(PyExc_AttributeError)){
>
> DBG("method %s is not implemented, trying default one\n",name);
> return true;
> }
>
> PyErr_Print();
> }
> else {
> if(o && PyBool_Check(o) && (o == Py_True)) {
>
> ret = true;
> }
>
> Py_DECREF(o);
> }
>
> return ret;
> }
>
> void PythonScriptThread::run() {
> PYLOCK;
> DBG("PythonScriptThread - calling python function.\n");
> callPyEventHandler("run","");
> // PyObject_CallObject(py_thread_object, NULL);
> DBG("PythonScriptThread - thread finished..\n");
> }
>
> instead of trunk:
>
> 74 sayer void PythonScriptThread::run() {
> 79 sayer PYLOCK;
> 79 sayer DBG("PythonScriptThread - calling python function.\n");
> 74 sayer PyObject_CallObject(py_thread_object, NULL);
> 79 sayer DBG("PythonScriptThread - thread finished..\n");
> 74 sayer }
>
> looks like the old version (above, r74) was rewritten, but now does work
> differently:
>
> ------------------------------------------------------------------------
> r79 | sayer | 2006-09-13 20:15:13 +0200 (Wed, 13 Sep 2006) | 2 lines
>
> createScriptThread made safer.
>
> ------------------------------------------------------------------------
> r74 | sayer | 2006-09-12 01:13:05 +0200 (Tue, 12 Sep 2006) | 5 lines
>
> * dialout API in IVR.
> * createThread function to create additionally running Python threads (e.g.
> servers)
> This function expects a python callable and executes it in a new thread.
>
> so I think now you need to pass it a callable (a function itself), not a
> python object with a run() function, maybe like this?
>
> def mycallable():
> print "hello"
>
> ivr.createThread(mycallable)
>
> so much for createThread archeology...
>
> Stefan
>
>
>> Cheers
>> Jason
>>
>>
>>
>>
>>
>> to run an xmlrpc server that would report some things about ivr
>> sessions (which call e.g. the onRegistrationEvent function). no idea
>> why i had to use the extra run_obj object, but probably because of
>> the run() function.
>>
>> Stefan
>>
>>
>> cheers
>> Jason
>>
>>
>> On Tue, Jul 8, 2008 at 4:25 PM, Raphael Coeffic <[EMAIL PROTECTED]
>> <mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]
>>
>> <mailto:[EMAIL PROTECTED]>>> wrote:
>>
>>
>> Hi Jason,
>>
>> i must confess that i have no idea what the createThread
>> function is
>> for (we should ask Stefan, as he added this function). The only
>> thing which i know for sure is that those threads are only
>> started
>> on start up (onLoad function of the IVR factory...).
>>
>>
>> But you can use just plain normal python threads. For this,
>> have a
>> look at:
>> http://docs.python.org/lib/module-threading.html
>> http://docs.python.org/lib/module-thread.html
>>
>> Cheers
>> Raphael.
>>
>> Jason Penton wrote:
>>
>> Hi *
>>
>> can somebody give me a heads up on creating a thread in
>> python
>> app for SEMS
>>
>> I have the following:
>>
>> class TestThread:
>> def run(self):
>> info("test thread executing")
>>
>>
>> #create test thread
>> testThread = TestThread()
>> createThread(testThread)
>>
>> the problem is that the it seems the thread never
>> executes the
>> code???????
>>
>> cheers
>> Jason
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Semsdev mailing list
>> [email protected] <mailto:[email protected]>
>> <mailto:[email protected] <mailto:[email protected]>>
>>
>> http://lists.iptel.org/mailman/listinfo/semsdev
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Semsdev mailing list
>> [email protected] <mailto:[email protected]>
>> http://lists.iptel.org/mailman/listinfo/semsdev
>>
>>
>> -- Stefan Sayer
>> VoIP Services
>>
>> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>> www.iptego.com <http://www.iptego.com>
>>
>> iptego GmbH
>> Am Borsigturm 40
>> 13507 Berlin
>> Germany
>>
>> Amtsgericht Charlottenburg, HRB 101010
>> Geschaeftsfuehrer: Alexander Hoffmann
>>
>>
>>
> --
> Stefan Sayer
> VoIP Services
>
> [EMAIL PROTECTED]
> www.iptego.com
>
> iptego GmbH
> Am Borsigturm 40
> 13507 Berlin
> Germany
>
> Amtsgericht Charlottenburg, HRB 101010
> Geschaeftsfuehrer: Alexander Hoffmann
>
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev