Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Implement a job scheduler, which takes in a function f and an integer n
- # and calls f after n milliseconds
- from timeit import default_timer as timer
- def f(n):
- if n < 0 or n != int(n):
- return "Error using the function 'f'"
- elif n == 0:
- return "Ending time: " + str(timer())
- else:
- start = timer()
- print("Starting time = " + str(start))
- while 1000 * (timer() - start) < n:
- continue
- return f(0)
- # MAIN FUNCTION
- millis = [10, 50, 500, 1000, 3000, 5000]
- for milli in millis:
- print("**** milliseconds = " + str(milli) + " ****")
- print(f(milli))
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement