Bottom Page

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
Quote
#2
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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)