Improve compatibility with CPython 2.7 and 3.x

This commit is contained in:
Noah
2021-01-06 13:37:21 +01:00
parent 3e4dd4c0bc
commit bf0c4087b4
5 changed files with 12 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ import time
import gc
from math import ceil
if not hasattr(time, 'ticks_ms'):
if not hasattr(time, 'sleep_ms') or not hasattr(time, 'ticks_ms'):
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
time.ticks_ms = lambda: int(time.time() * 1000)
time.sleep_ms = lambda x: time.sleep(x/1000.0)