Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How can I call a method every x seconds?

created() {
    this.interval = setInterval(() => this.getBitcoins(), 1000);
},
Comment

Call a function after every x seconds

from threading import Timer

class RepeatedTimer(object):
    def __init__(self, interval, function, *args, **kwargs):
        self._timer     = None
        self.interval   = interval
        self.function   = function
        self.args       = args
        self.kwargs     = kwargs
        self.is_running = False
        self.start()

    def _run(self):
        self.is_running = False
        self.start()
        self.function(*self.args, **self.kwargs)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self._timer.start()
            self.is_running = True

    def stop(self):
        self._timer.cancel()
        self.is_running = False
Comment

PREVIOUS NEXT
Code Example
Python :: property values 
Python :: packing a tuple 
Python :: assert isinstance python 
Python :: generate a hash/secret python 
Python :: multiplying float variables python and print 
Python :: 0 in python 
Python :: geopandas bbox 
Python :: await not working python 
Python :: why do we need to preprocess data 
Python :: djangorestframework install command 
Python :: python iterate through lists 
Python :: python created nested directory 
Python :: how to downlaod file using python 
Python :: python solve rubicks cube 
Python :: pyqt5.direct connection 
Python :: python dash bootstrap buttons with icons 
Python :: isat in panadas datframe 
Python :: torch.cuda.randn 
Python :: if len(i1.getbands()) == 1 
Python :: use ipython magic in script 
Python :: gcp jupyter use python variables in magic bigquery 
Python :: print("python is good") 
Python :: Python Write to File Way01 
Python :: apache virtual host django wsgi 
Python :: Python Print year, month, hour, minute and timestamp 
Python :: Get hours, minutes, seconds, and microseconds using time class 
Python :: Fill specific area under curve 
Python :: django filter form view 
Python :: matplotlib no gui 
Python :: set DJANGO_SETTINGS_MODULE=mysite.settings django-admin 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =