<div dir="ltr">Late to answer. Seems no one did, so I'd say don't write event listeners that run in a Python interpreter that FreeSWITCH knows nothing about and uses threading. <div><br></div><div>I looked at doing something similar in Python in the 1.2 days and after a couple of roadblocks like this, I took the advice of the wiki and the developers and developed what I needed in Lua. It worked out very well.</div><div><br></div><div>Python gets some love in Confluence, so I assume people use it, though. I know for a fact that you can start a Lua event listener by executing a luarun command via Python ESL API. Maybe it would also work in this case to run a Python script in the interpreter managed by mod_python. Let FS manage thread state.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 11, 2017 at 1:03 AM, Mohd Kamal Bin Mustafa <span dir="ltr"><<a href="mailto:kamal.mustafa@gmail.com" target="_blank">kamal.mustafa@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have this python code:-<br>
<br>
import time<br>
import json<br>
import logging<br>
import threading<br>
<br>
from freeswitchESL import ESL<br>
<br>
class EventThread(threading.Thread):<br>
def __init__(self, target, args):<br>
super(EventThread, self).__init__()<br>
self.target = target<br>
self.args = args<br>
<br>
def run(self):<br>
print("Running target")<br>
self.target(*self.args)<br>
<br>
def on_channel_park(e):<br>
uuid = e.getHeader('Unique-ID')<br>
print("Ringing")<br>
conn.execute('ring_ready ', '', uuid)<br>
conn.execute('sleep', '5500', uuid)<br>
conn.execute('answer', '', uuid)<br>
print("answered, playing media ...")<br>
media_url = '<a href="http://www.noiseaddicts.com/samples_1w72b820/17.mp3" rel="noreferrer" target="_blank">http://www.noiseaddicts.com/<wbr>samples_1w72b820/17.mp3</a>'<br>
resp = conn.execute("playback", media_url, uuid)<br>
print(resp.getHeader("Reply-<wbr>Text"))<br>
print("playback done")<br>
print(resp)<br>
<br>
if __name__ == '__main__':<br>
conn = ESL.ESLconnection('127.0.0.1', '8021', 'mypass')<br>
conn.events('plain', 'all')<br>
while True:<br>
e = conn.recvEvent()<br>
uuid = e.getHeader('Unique-ID')<br>
events_message = json.loads(e.serialize('json')<wbr>)<br>
event_name = events_message['Event-Name'].<wbr>lower()<br>
method_name = 'on_%s' % event_name<br>
print(method_name)<br>
<br>
if event_name == 'channel_park':<br>
print("spawning thread")<br>
t = EventThread(on_channel_park, args=(e,))<br>
t.start()<br>
<br>
if event_name == 'playback_stop':<br>
conn.execute("hangup", "", uuid)<br>
print("Hanging up")<br>
<br>
Above, the code will stuck at conn.execute('ring_ready ', '', uuid) in<br>
on_channel_park(). It never went pass through until I hangup the call.<br>
In freeswitch log, it stopped at executing park().<br>
<br>
But if I moved ring_ready, sleep, answer outside of the thread it will<br>
work, i.e I can hear a playback:-<br>
<br>
def on_channel_park(e):<br>
uuid = e.getHeader('Unique-ID')<br>
print("answered, playing media ...")<br>
media_url = '<a href="http://www.noiseaddicts.com/samples_1w72b820/17.mp3" rel="noreferrer" target="_blank">http://www.noiseaddicts.com/<wbr>samples_1w72b820/17.mp3</a>'<br>
resp = conn.execute("playback", media_url, uuid)<br>
print(resp.getHeader("Reply-<wbr>Text"))<br>
print("playback done")<br>
print(resp)<br>
<br>
if __name__ == '__main__':<br>
conn = ESL.ESLconnection('127.0.0.1', '8021', 'mypass')<br>
conn.events('plain', 'all')<br>
while True:<br>
e = conn.recvEvent()<br>
uuid = e.getHeader('Unique-ID')<br>
events_message = json.loads(e.serialize('json')<wbr>)<br>
event_name = events_message['Event-Name'].<wbr>lower()<br>
method_name = 'on_%s' % event_name<br>
print(method_name)<br>
<br>
if event_name == 'channel_park':<br>
print("Ringing")<br>
conn.execute('ring_ready ', '', uuid)<br>
conn.execute('sleep', '5500', uuid)<br>
conn.execute('answer', '', uuid)<br>
print("spawning thread")<br>
t = EventThread(on_channel_park, args=(e,))<br>
t.start()<br>
<br>
Any idea why this happen ?<br>
<br>
______________________________<wbr>______________________________<wbr>_____________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" rel="noreferrer" target="_blank">http://www.<wbr>freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" rel="noreferrer" target="_blank">http://confluence.freeswitch.<wbr>org</a><br>
<a href="http://www.cluecon.com" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.<wbr>freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/<wbr>mailman/listinfo/freeswitch-<wbr>users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.<wbr>freeswitch.org/mailman/<wbr>options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
</blockquote></div><br></div>