From: Bernd S. <be...@bs...> - 2022-05-16 14:02:47
|
I try to make asterisk wait for a call, answer some numbers, and Hangup. I also want to run my python3 and pyst 0.8.0 script until the Hangup happens. I do it in the following way: After running connect() on asterisk.manager.Manager() I use register.event() to register a callback for 'Hangup' Then I change the dialplan for a spcific extension and context with command("dialplan remove extension ...") and command("dialplan add extension ...") for each line of Answer() Set(TIMEOUT(absolute)=%d) Set(i=1) While(True) SayNumber(${i}) Wait(1) Set(i=$[${i} + 1]) EndWhile() Hangup() Now I start message_loop() And it works, sometimes without any error. But sometimes after the Hangup callback is called I get the following exception: Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3/dist-packages/asterisk/manager.py", line 293, in _receive_data for line in self._sock : File "/usr/lib/python3.7/socket.py", line 583, in readinto self._checkClosed() ValueError: I/O operation on closed file. And when I get the exception, in some cases even worse the python script hangs. I already tested this 5 years before with python2 and an older pyst version. And I believe the Exceptions occur now more often. The good thing is, that before the python script hangs, it has already communicated with asterisk. And asterisk works fine. And so I made a brutal workaround, and kill my PID from the "Hangup" callback afer waiting a short time. But this workaround is ugly. Do you think there is a design error in my algorithm ? Do you have an idea, what I could try ? Regards Bernd Bernd Schumacher Communications Media Solutions Hewlett-Packard GmbH ber...@hp... |