I want to create a 30sec timer in Python with async
but I don't know how I can do.
I tried with this code but it blocks all the code:
def restore_presences(self, loop):
async def func():
db, c = self.connect()
c.execute('SELECT Presenza FROM Teachers')
presences = c.fetchall()
for item in presences:
c.execute('UPDATE Teachers SET Presenza = ?', ('no',))
db.commit()
db.close()
threading.Thread(target=lambda loop: loop.run_until_complete(func()), args=(loop,)).start()
# THIS BLOCKS MY CODE
t = Timer(30, self.restore_presences, args=[asyncio.get_event_loop()])
t.start()
t.join()
# THIS BLOCKS MY CODE
The async
function runs perfectly.