N
N
Nikita Presnov2020-12-01 11:58:37
Python
Nikita Presnov, 2020-12-01 11:58:37

How to use sched?

There is such a simple piece of code.

import sched, time  
s = sched.scheduler(time.time, time.sleep)
def print_time(a='default'):
    print("From print_time", time.time(), a)
    
def print_some_times():
    tim = time.time()
    # print(tim)
    s.enter(10, 1, print_time)
    s.enter(5, 2, print_time, argument=('positional',))
    s.enter(5, 1, print_time, kwargs={'a': 'keyword'})
    s.run()
    print(time.time() - tim)

tim1 = time.time()
for i in range(5):
    print_some_times()
    print(time.time() - tim1)

Where do I need to insert time.sleep(0.1) so that the period does not change?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question