Issue
Is there a solution to the asyncio.sleep() function. I am sending multiple commands to the func "async def send" as "command" and it should send one after the other. It only sends one and after 5 sec the rest.
EDIT:
async def send(self, command, count):
for x in range(count):
await self.ws.send(command)
lb1.insert(END, command)
await asyncio.sleep(5)
This is my func that passes the values:
def sending():
command = entry.get("1.0", 'end-1c')
p = command.split('@')
count = 0
for x in p:
print(f'Sent -> {x}')
asyncio.ensure_future(echo.send(x, count))
count+=1
btn2.config(command=sending)
I am expecting: for example: 4 input commands, first one gets sent out and the delay starts for 5 sec and the secound one should be sent out -> delay 5 sec -> ...
FINAL EDIT:
async def send(self, command):
p = command.split('@')
for x in p:
await self.ws.send(x)
lb1.insert(END, x)
await asyncio.sleep(5)
Now it works :) I found my mistake
def sending():
command = entry.get("1.0", 'end-1c')
print(f'Sent -> {command}')
asyncio.ensure_future(echo.send(command))
Solution
Did you intend:
async def send(self, command, count):
for i in range(count):
await self.ws.send(command)
lb1.insert(END, command)
await asyncio.sleep(5)
However, the use of insert
makes me think this is a tkinter app. If that is correct, then this is the wrong approach. Nothing will get updated until this function returns and gets back to the main loop. You main need to use tk.after
instead.
Answered By - Tim Roberts
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.