For loop doesn't work as it should.
invictusro opened this issue · 3 comments
Hello guys so I do have the following problem. I have a ssh command which takes time and I want to know the exact time of it's output so I don't have to wait that long and I want to check if it's finished from 2 to 2 seconds and I was wondering why this while doesn't work ? It prints I as being just 1 and not the other values (it stops with no code error whatsoever) I have also tried with a for loop and I get printed 2 values only.
i = 0
size, data = channel.read()
while(size > 0 and i < 20):
time.sleep(2)
i =+ i
print(i)
if("Successful" in data.decode("utf-8")):
print(datetime.now().strftime("%d/%m/%Y %H:%M:%S") +
"- Proxy created - " + username + ":" + password + ":" + orderPort + " - " +index)
return "success"
size, data = channel.read()
This prints only first 0 and then 1 and then stops with no code error and no output.
for i in range(20):
time.sleep(2)
print(i)
size, data = channel.read()
if("Successful" in data.decode("utf-8")):
print(datetime.now().strftime("%d/%m/%Y %H:%M:%S") +
"- Proxy created - " + username + ":" + password + ":" + orderPort + " - " +index)
return "success"
This works but this doesn't contain any loop at all:
time.sleep(15)
size, data = channel.read()
if("Successful" in data.decode("utf-8")):
print(datetime.now().strftime("%d/%m/%Y %H:%M:%S") +
"- Proxy created - " + username + ":" + password + ":" + orderPort + " - " +index)
return "success"
Thank you!
Please use the mail group for discussion and questions, the issue tracker is for issues with the library. Thanks!
But what is this? As it’s a simple loop and code provided by your library.
That code is not provided by the library. The repository's issue tracker is for issues with the library, not debugging code written by others.
See provided example on how to correctly read data and API documentation on how to correctly wait for a remote command to finish.
Any further questions and discussion should happen on the mail group. Thank you for the interest.