I am been trying to run two functions simultaneously but one never seems to work unless I stop the other. The first function sends an email every 30 seconds while the second prints a simple statement every 5 seconds. In combination, per every 6 "Hello Worlds" outputs one email should be sent.
However, I never get an email unless the printing is changed to stop early, such as ending after 10 seconds. What can I do to have both running concurrently without stopping?
async def timer():
end = time.time() + 30
while True:
if time.time() >= end:
sendmail(name, filepath + "\\" + name, receiver)
end = time.time() + 30
async def runs():
while True:
print("Hello World")
time.sleep(5)
loop = asyncio.get_event_loop()
loop.create_task(runs())
loop.create_task(timer())
loop.run_forever()
asyncprovides cooperative concurrency.timeris not written cooperatively - it never suspends, e.g. viaasyncio.sleep(0).sendmail.