简体   繁体   中英

I want to control the execution interval of Python code in detail. (I used time.sleep)

There is a certain While infinite loop statement, but given the Time.sleep(0.001) condition, it only executes 700 times per second. I want to run 5,000 to 50,000 times per second, but the argument of time.sleep() can't be lower than 0.001?

import time

i = int()
while True:
    time.sleep(0.001)
    #~
    #Code Block(It's private because it's code I'm reluctant to reveal.)
    #~
    print("%d"&i) #700 print() calls per second.

time.sleep(0.001) sleeps for 1 ms or 1/1000 sec. Therefore you cannot get more than 1000 loops per second.

but the argument of time.sleep() can't be lower than 0.001

This is not true. The argument to time.sleep() is a float: https://docs.python.org/3/library/time.html#time.sleep

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM