I have a Python script that sends a mail request to my API every 1 minute:
while True:
data = requests.post("URL_HERE", json={
"api_key":"XXXX",
"concat": 1,
"messages": "HI"
})
time.sleep(60)
Everything works fine, but every 2 hours (more or less) there are 2 entries of the same minute. Example:
2017-03-22 11:34:46.977255
2017-03-22 11:37:47.231694
2017-03-22 11:37:47.231694
2017-03-22 11:39:48.849003
2017-03-22 11:40:48.907895
...
2017-03-23 13:59:59.150108
2017-03-23 14:00:00.120431
2017-03-23 14:00:00.942033
I suppose this is because the code inside the "while" takes a couple of milliseconds to execute, so it will have two entries every 2-3 hours per minute.
Does anyone know how I can fix this? I can not use cronjobs.
Could it be an asynchronous task?
And if I want this program to run forever, Okey use "while", or do I need to create Daemon o something like that?
source
share