I understand why it is breaking the first time.sleep after 1 second. But why subsequent utime.sleep() always breaks after ~100ms when there is a pending notification? It will continue like that until the notification will be get in the child thread. Was this behavior intended to shorten the notification handling delay? I tested the following code from the thread template in the wiki and I got the same behavior:
From the wiki's thread template:
# ---------------------------------------------------------------
# - Using sleep in thread function -
# ---------------------------------------------------------------
# 'utime.sleep(sec, True)' & 'utime.sleep_ms(ms, True)' functions returns the
# actual ellapsed sleep time. The sleep will be interrupted if
# a notification is received and the returned value will be less
# than the requested one
# ---------------------------------------------------------------
# Example:
print("TH_FUNC: Loop started")
for i in range(0, 5):
print("TH_FUNC: Loop no:", i)
sleep_time = utime.sleep_ms(10000, True)
if sleep_time < 10000:
# Notification received while sleeping
print("TH_FUNC: Notification while sleeping", st)
# Sleep for the remaining interval if needed
utime.sleep_ms(10000 - sleep_time)
print("TH_FUNC: Loop ended")
For now, I'm fixing this by using a custom sleep function:
def sleep(sleep_time_ms):
time = 0
while time < sleep_time_ms:
time += utime.sleep_ms(sleep_time_ms - time, True)
This will end to sleep the wanted time.
Thank you for your reply,
not sure if it is an issue or a feature.
Here's a test code I made:
Output:
I understand why it is breaking the first time.sleep after 1 second. But why subsequent utime.sleep() always breaks after ~100ms when there is a pending notification? It will continue like that until the notification will be get in the child thread. Was this behavior intended to shorten the notification handling delay? I tested the following code from the thread template in the wiki and I got the same behavior:
From the wiki's thread template:
For now, I'm fixing this by using a custom sleep function:
This will end to sleep the wanted time.
Thank you for your reply, not sure if it is an issue or a feature.