How can I write a function that does nothing for a given length of time?
本问题已经有最佳答案,请猛点这里访问。
以下是我尝试的(python):
1 2 3 4 5 6 | import time def wait(seconds): start_time = time.time() while start_time + seconds <= time.time(): pass |
但这只是立即放弃。
以下代码将在指定的时间段内有效睡眠
1 2 | import time time.sleep(1) # delays for 1 second |