Python Forum
Possible to use asyncio as a faster while loop? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Possible to use asyncio as a faster while loop? (/thread-22909.html)



Possible to use asyncio as a faster while loop? - JackMack118 - Dec-03-2019

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



RE: Possible to use asyncio as a faster while loop? - JackMack118 - Dec-03-2019

OK, I'm guessing to make this faster with some kind of asynchronous function in Asyncio to make more 'workers' isn't going to work here, though I'm wondering how I can get this to work faster?

I'm studying up on generators now, am I getting warmer?

Any help please.