Created
April 12, 2013 10:50
-
-
Save stamat/5371218 to your computer and use it in GitHub Desktop.
Python setInterval() equivalent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
def set_interval(func, sec): | |
def func_wrapper(): | |
set_interval(func, sec) | |
func() | |
t = threading.Timer(sec, func_wrapper) | |
t.start() | |
return t |
I get an error while doing this;
Exception in thread Thread-13:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 1254, in run
self.function(*self.args, **self.kwargs)
File "myprogram.py", line 56, in func_wrapper
func()
TypeError: 'NoneType' object is not callable
I get an error while doing this;
Exception in thread Thread-13: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 1254, in run self.function(*self.args, **self.kwargs) File "myprogram.py", line 56, in func_wrapper func() TypeError: 'NoneType' object is not callable
is there other way to use it on async functions?
this not will work as expected, it python no such analog
Just make a function in an infinite loop:
def one_second_interval():
.....print("x")
.....time.sleep(1)
while True:
.....one_second_interval()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An other option: Event scheduler. https://docs.python.org/3/library/sched.html