Sorry for this beginner's question...
I work with a ESP32-WROOM
This is the code reduced to its simplest version :
Code: Select all
# test asyncio threads
import time
import machine
import sys
from machine import I2C, Pin, Timer, Pin, ADC
import micropython
import uasyncio as asyncio
async def fn_1() :
while True :
print("fn_1")
print(time.time())
await asyncio.sleep(4)
loop = asyncio.get_event_loop()
loop.create_task(fn_1())
try :
loop.run_forever()
except KeyboardInterrupt :
loop.close()
print("keyboard interrupt")
sys.exit()
except Exception as e:
print(e)
loop.close()
sys.exit()
fn_1
41
fn_1
45
fn_1
49
fn_1
53
keyboard interrupt
>>>
next time :
fn_1
152
fn_1
152
fn_1
156
fn_1
156
keyboard interrupt
>>>
etc
...as if the loop continues to run in the background, without stopping...
What is missing in my code to completely stop loops ??
Thanks !
JP