[Freeswitch-users] Python-ESL: ESLconnection.execute() blocked when handling channel_park under thread
Mohd Kamal Bin Mustafa
kamal.mustafa at gmail.com
Tue Apr 11 11:03:11 MSD 2017
I have this python code:-
import time
import json
import logging
import threading
from freeswitchESL import ESL
class EventThread(threading.Thread):
def __init__(self, target, args):
super(EventThread, self).__init__()
self.target = target
self.args = args
def run(self):
print("Running target")
self.target(*self.args)
def on_channel_park(e):
uuid = e.getHeader('Unique-ID')
print("Ringing")
conn.execute('ring_ready ', '', uuid)
conn.execute('sleep', '5500', uuid)
conn.execute('answer', '', uuid)
print("answered, playing media ...")
media_url = 'http://www.noiseaddicts.com/samples_1w72b820/17.mp3'
resp = conn.execute("playback", media_url, uuid)
print(resp.getHeader("Reply-Text"))
print("playback done")
print(resp)
if __name__ == '__main__':
conn = ESL.ESLconnection('127.0.0.1', '8021', 'mypass')
conn.events('plain', 'all')
while True:
e = conn.recvEvent()
uuid = e.getHeader('Unique-ID')
events_message = json.loads(e.serialize('json'))
event_name = events_message['Event-Name'].lower()
method_name = 'on_%s' % event_name
print(method_name)
if event_name == 'channel_park':
print("spawning thread")
t = EventThread(on_channel_park, args=(e,))
t.start()
if event_name == 'playback_stop':
conn.execute("hangup", "", uuid)
print("Hanging up")
Above, the code will stuck at conn.execute('ring_ready ', '', uuid) in
on_channel_park(). It never went pass through until I hangup the call.
In freeswitch log, it stopped at executing park().
But if I moved ring_ready, sleep, answer outside of the thread it will
work, i.e I can hear a playback:-
def on_channel_park(e):
uuid = e.getHeader('Unique-ID')
print("answered, playing media ...")
media_url = 'http://www.noiseaddicts.com/samples_1w72b820/17.mp3'
resp = conn.execute("playback", media_url, uuid)
print(resp.getHeader("Reply-Text"))
print("playback done")
print(resp)
if __name__ == '__main__':
conn = ESL.ESLconnection('127.0.0.1', '8021', 'mypass')
conn.events('plain', 'all')
while True:
e = conn.recvEvent()
uuid = e.getHeader('Unique-ID')
events_message = json.loads(e.serialize('json'))
event_name = events_message['Event-Name'].lower()
method_name = 'on_%s' % event_name
print(method_name)
if event_name == 'channel_park':
print("Ringing")
conn.execute('ring_ready ', '', uuid)
conn.execute('sleep', '5500', uuid)
conn.execute('answer', '', uuid)
print("spawning thread")
t = EventThread(on_channel_park, args=(e,))
t.start()
Any idea why this happen ?
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list