vscode-pyolite icon indicating copy to clipboard operation
vscode-pyolite copied to clipboard

`time.sleep(...)` fails to suspend execution for indicated number of seconds.

Open dynamicwebpaige opened this issue 4 years ago • 3 comments

Expected behavior: When importing Python's time module and using the sleep() function, I expect to suspend execution of the calling thread for the given number of seconds.

Experienced behavior: 42 seconds passed in the blink of an eye. I knew it was a special number, but not that special! ☺

Reproducible example:

import time
print("The meaning of life...")
time.sleep(42)
print("...is learning the superpower of patience.")

image

dynamicwebpaige avatar Oct 19 '21 04:10 dynamicwebpaige

This is caused by https://github.com/pyodide/pyodide/issues/1720

🤔 the semantic colorization in that screenshot looks off. Possibly worth filing an issue on Pylance?

joyceerhl avatar Oct 19 '21 05:10 joyceerhl

An alternative to time.sleep() is to use await asyncio.sleep():

import asyncio
print("The meaning of life...")
await asyncio.sleep(42)
print("...is learning the superpower of patience.")

jtpio avatar Oct 19 '21 08:10 jtpio

🤔 the semantic colorization in that screenshot looks off. Possibly worth filing an issue on Pylance?

@joyceerhl 😄 Upvotes appreciated! Rich is on it: https://github.com/microsoft/pylance-release/issues/1874

@jtpio : Thank you! Will use the workaround in my notebook example.

dynamicwebpaige avatar Oct 19 '21 17:10 dynamicwebpaige