0

Right, I'm quite new and I've been looking around for an answer but I just can't seem to find one that fits me.

This question is pretty much the same as mine, but I need to execute a function every... Let's say 1.2 seconds and without interrupting or blocking the whole while loop.

The reason I won't use modules (except for time) is because the only available ones to me are: builtins, math, matplotlib.pyplot, numpy, operator, processing, pygal, random, re, string, time, turtle and urllib.request.

Is there such a way?

Community
  • 1
  • 1
MrWhiteee
  • 67
  • 4

2 Answers2

1

If you have turtle available, then you have tkinter available as turtle.TK. You can then use root.after(1200, function. args) to execute function(*args) every 1.2 seconds. Searching SO for [tkinter] root.after will give numerous questions with helpful examples. However, once you do that, you must make everything event driven and event handlers should not take so long as to block the event loop.

EDIT: turtle wraps tkinter.after as turtle.ontimer(function, milleseconds). The function cannot take arguments. If this is a 'homework' problem of some sort, this may be the intended solution. There is an example here.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
0

Use the module time. You have it on your list.

import time
def function():
 print(1)
while True:
 time.sleep(1.2)
 function()
whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44