Skip to content

Commit

Permalink
fix: fixed loop termination when timeout limit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
mmubarak0 committed Jul 7, 2024
1 parent de88a43 commit bce9fb8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions examples/send_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
python3 send_ussd.py http://admin:[email protected]/ *4# 7 1
"""
import sys
import time
import itertools
import threading
Expand All @@ -30,8 +29,9 @@
'codes', metavar='code',
type=str, nargs='+', help='USSD code to send'
)
parser.add_argument('--timeout', type=int, default=15)
args = parser.parse_args()
MAX_WAIT_TIME = 15
MAX_WAIT_TIME = args.timeout
DONE = False


Expand Down Expand Up @@ -63,21 +63,24 @@ def animate():
t.start()
else:
print('Error: Cannot send USSD code')
break
except Exception as e:
print(f'Error: {e}')
break

# Wait for the response from the service provider.
while int(client.ussd.status().get('result', '1')) >= 1:
if wait_time >= MAX_WAIT_TIME:
print('Error: Timeout Limit Exceeded')
DONE = True
t.join()
print('Error: Timeout Limit Exceeded')
break
wait_time += 1
time.sleep(1)
if DONE:
continue
else:
DONE = True
t.join()
break
DONE = True
t.join()

# Print the response.
response = client.ussd.get()
Expand Down

0 comments on commit bce9fb8

Please sign in to comment.