Python Forum
Possible to use asyncio as a faster while loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible to use asyncio as a faster while loop?
#1
I've made this loop to pull random 1000 lines (made in other part of code) into a Textbox. It works flawlessly, though it takes maybe 10 seconds to do it.

Possible to make an Asyncio solution to speed up the loop?


def myClick():
    oneK = 1
    while oneK < 1000:
        keywordbox.insert(END, (fileA(kwTXT1)) + ' ' + (fileB(kwTXT2)) + ' ' +  (fileC(kwTXT3))  + ' ' + (fileD(kwTXT4)) + ' ' + (fileE(kwTXT5)) + '\n')
        oneK += 1
Thank you for reading.

Wish I could edit my OP, but here is the code that gets the lines from the text file too, I think this would need to be in the loop(?) I guess too?

def fileA(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)
def fileB(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)
def fileC(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)
def fileD(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)
def fileE(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)
def fileF(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)


def myClick():
    oneK = 1
    while oneK < 1000:
        keywordbox.insert(END, (fileA(kwTXT1)) + ' ' + (fileB(kwTXT2)) + ' ' +  (fileC(kwTXT3))  + ' ' + (fileD(kwTXT4)) + ' ' + (fileE(kwTXT5)) + '\n')
        oneK += 1
Reply


Messages In This Thread
Possible to use asyncio as a faster while loop? - by JackMack118 - Dec-03-2019, 12:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  asyncio not being faster than synchronous calls mikisDW 0 708 Sep-26-2022, 09:14 AM
Last Post: mikisDW
  Asyncio: Queue consumer gets out of while loop without break. Where exactly and how? saavedra29 2 2,607 Feb-07-2022, 07:24 PM
Last Post: saavedra29

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020