How can I run a while loop which edits a aiosqlite database but is not in a async function

41 Views Asked by At
if True:
    import shortcuts.startupload
    from shortcuts.startupload import *
    import threading
    import time

**def background():
    while True:
        if 1 == 1:
            if 1 == 1:
                gwtimes = await aiosqlite.connect('gwtimes.db')
                async with gwtimes.cursor() as gwcursor:
                    await gwcursor.execute("UPDATE gwtimes SET time=time+50")
                await gwtimes.commit()
                async with gwtimes.cursor() as gwcursor:
                    await gwcursor.execute("SELECT time FROM gwtimes")
                    number = await gwcursor.fetchone()
                print(number)**

def foreground():
    (other code) 

b = threading.Thread(name='background', target=background)
f = threading.Thread(name='foreground', target=foreground)

b.start()
f.start()


    
bot.run(hidden token)

Above is most of the whole thing

I need it to (in the background) add 50 to all values in the column every 1 second and then print the time so I can test its working, however I dont get how to use async and await with this as the error is saying:

    gwtimes = await aiosqlite.connect('gwtimes.db')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside async function```
0

There are 0 best solutions below